在 XPath 之后选择带有类 ajaxcourseindentfix 的 div 元素,并将其从先决条件中拆分出来,并在先决条件之后为我提供所有内容。
div = soup.select("div.ajaxcourseindentfix")[0]
" ".join([word for word in div.stripped_strings]).split("Prerequisite: ")[-1]
我的 div 不仅可以有先决条件,还可以有以下拆分点:
先决条件核心条件
核心
条件
现在,只要我有Prerequisite,上面的 XPath 就可以正常工作,但是只要上面三个中的任何东西出现,XPath 就会失败并给我整个文本。
有没有办法在 XPath 中放置多个分隔符?或者我该如何解决?
示例页面:
并存 URL:http ://catalog.fullerton.edu/ajax/preview_course.php?catoid=16&coid=96106&show
先决条件网址:http ://catalog.fullerton.edu/ajax/preview_course.php?catoid=16&coid=96564&show
两者:http ://catalog.fullerton.edu/ajax/preview_course.php?catoid=16&coid=98590&show
[旧线程] -如何获取没有 HTML 标记的文本