【发布时间】:2020-01-05 07:10:15
【问题描述】:
我正在尝试从 WSJ 网站上的文章中抓取文本内容。例如考虑以下 html 源代码:
<div class="article-content ">
<p>BEIRUT—
Carlos Ghosn,
who is seeking to clear his name in Lebanon, would face a very different path to vindication here, where endemic corruption and the former auto executive’s widespread popularity could influence the outcome of a potential trial. </p> <p>Mr. Ghosn, the former chief of auto makers
我正在使用以下代码:
res = requests.get(url)
html = BeautifulSoup(res.text, "lxml")
classid = "article-content "
item = html.find_all("div", {"class":classid})
这将返回一个空项目。我看到了其他一些帖子,人们建议 adding delays 和 others 但这些在我的情况下不起作用。计划将抓取的文本用于一些 ML 项目。
我订阅了 WSJ,并且在运行上述脚本时已登录。
对此的任何帮助将不胜感激!谢谢
【问题讨论】:
-
关闭浏览器中的javascript并重新加载页面。你想要的内容还在吗?
-
是的,检查了渲染页面和html源代码。
标签: python web-scraping beautifulsoup python-requests