Web抓取' window'目的
我正在尝试获取像这样的新闻文章的身体文字:
noreferrer“> https://elpais.com/espana/2022-07-01/yolanda-diaz-lanza-su-proyecto-politico-politico-sumar-sumar-y-convoca-convoca-el-primer-acto-acto.html 源代码,可以在“文章”之后找到。
我尝试使用BS4 Beautifulsoup,但看起来它无法访问文章Body信息所在的“窗口”对象。我可以使用字符串函数来获取文本:
text = re.search('"articleBody":"(.*)","keywords"', source_code)
其中源_code是包含URL源代码的字符串。但是,与在页面允许时使用BS4方法相比,此方法看起来非常低效。有什么建议吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您对BeautifulSoup无法处理窗户对象的正确性是正确的。实际上,您需要将硒用于这种事情。这是一个关于如何使用Python 3进行的示例(如果您想在Python 2中工作,则必须稍微调整它):
希望这会有所帮助!
You're right about BeautifulSoup not being able to handle window objects. In fact, you need to use Selenium for that kind of thing. Here's an example on how to do so with Python 3 (you'll have to adapt it slightly if you want to work in Python 2):
Hope this helps!
尝试:
打印:
或:
Try:
Prints:
Or: