【发布时间】:2020-09-10 09:46:26
【问题描述】:
我正在尝试使用 BeautifulSoup 在本网站的 div 下获取 ul 中的文本:https://www.nccn.org/professionals/physician_gls/recently_updated.aspx
但我只得到一个空的 div。我的代码是:
page = requests.get("https://www.nccn.org/professionals/physician_gls/recently_updated.aspx")
soup=BeautifulSoup(page.content,"html.parser")
_div=soup.find("div",{"id":"divRecentlyUpdatedList"})
element = [i.text for i in b.find("a") for b in _div.find("ul")]
结果是:
HTML文件截图如下:div and ul
另外,在我试图从中获取内容的 div 之后有 javascript:
我也试过这样获取所有的 li:
l = []
for tag in soup.ul.find_all("a", recursive=True):
l.append(tag.text)
但我得到的文字不是我想要的。该div下的文本是否被javascript隐藏了?
欢迎任何帮助。非常感谢您。
【问题讨论】:
-
您要提取的文本是什么?
标签: javascript python web-scraping beautifulsoup