【发布时间】:2022-01-13 11:16:19
【问题描述】:
我正在尝试抓取以下网站:
www.londonstockexchange.com/news-article/THRG/net-asset-value-s/15242427
基本上我只想保存文本,即以下内容:
“贝莱德 Throgmorton Trust PLC 的未经审计的资产净值截至收盘时 2021 年 12 月 7 日的业务为: 938.74p 仅资本 947.82p 包括当年收入”
我已尝试使用以下代码,但是似乎无法解析该元素。任何想法为什么?
url = "https://www.londonstockexchange.com/news-article/THRG/net-asset-value-s/15242427"
page = requests.get(url) # Requests website
soup = BeautifulSoup(page.content, 'html.parser')
table = soup.find_all('div', attrs={'class':'news-body-content'})
table
尝试了各种方法,但是没有运气。希望有人能帮忙。
【问题讨论】:
-
相关内容是通过 JavaScript 加载的。这可以通过使用
curl或在关闭 JavaScript 的情况下查看网页来确定。对于此类页面,requests包不适合此类情况。您将需要另一个工具,例如selenium或 PyQt 的QWebView(例如 pythoncentral.io/pyside-pyqt-tutorial-qwebview)。加载内容后,您可以使用 BeautifulSoup 对其进行解析。
标签: python html web web-scraping beautifulsoup