以下是HTML:
<div class="ajaxcourseindentfix"> <h3>CPSC 353 - Introduction to Computer Security (3) </h3> <hr>Security goals, security systems, access controls, networks and security, integrity, cryptography fundamentals, authentication. Attacks: software, network, website; management considerations, security standards in government and industry; security issues in requirements, architecture, design, implementation, testing, operation, maintenance, acquisition, and services. <br> <br>Prerequisite: <a href="preview_course_nopop.php?catoid=16&coid=96570" onclick="acalogPopup()">CPSC 253U</a> <span style="display: none !important"> </span> or <a href="#" onclick="acalogPopup()" target="_blank">CPSC 254</a> <span style="display: none !important"> </span> and <a href="#" onclick="acalogPopup()" target="_blank">CPSC 351</a> <span style="display: none !important"> </span> , declared major/minor in CPSC, CPEN, or CPEI <br> </div>
我需要从此HTML中获取以下文本:
从第6行- 或从第7行- 和,在CPSC,CPEN或CPEI中声明为主要/次要
我可以使用以下XPath获得href [课程号:CPSC 254等…]:
# This xpath gives me all the tags followed by h3 and then I iterate through them in my script. //div[@class='ajaxcourseindentfix']/h3/following-sibling::text()[2]/following-sibling::*
更新资料
并且,然后输入具有以下XPath的文本:
# This xpath gives me all the text after the h3 tag. //div[@class='ajaxcourseindentfix']/h3/following-sibling::text()[2]/following-sibling::text()
我需要以与URL 1相同的方式来获取这些课程名称/前提条件。
通过这种方法,我先获取所有HREF,然后获取所有文本。有没有更好的方法来实现这一目标?我不想遍历2个XPath,先获取HREF,然后再获取Text,然后将其合并以形成必备字符串。
1 http://catalog.fullerton.edu/ajax/preview_course.php?catoid=16&coid=99648&show