是否可以用美丽的汤来提取多种类型的物品?
我一直在查看文档,但他们没有涵盖这个问题。我正在尝试提取所有文本和所有链接,但不是单独提取。我希望它们交错以保留上下文。我想最终得到一个文本和链接的交错列表。 BeautifulSoup 可以做到这一点吗?
I've been looking at documentation and they don't cover this issue. I'm trying to extract all text and all links, but not separately. I want them interleaved to preserve context. I want to end up with an interleaved list of text and links. Is this even possible with BeautifulSoup?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,这绝对是可能的。
分解此代码片段,您正在向网站(在本例中为 Google.com)发出
请求
,并使用 BeautifulSoup 解析响应
。您的要求是找到所有链接和文本并保留上下文。上述代码的输出将如下所示:Yes, this is definitely possible.
Breaking this code snippet down, you are making a
request
for a website (in this case Google.com) and parsing theresponse
back with BeautifulSoup. Your requirements were to find all links and text and keep the context. The output of the above code will look like this: