仅 Scrapy 正文文本 [英] Scrapy Body Text Only

查看:57
本文介绍了仅 Scrapy 正文文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 python Scrapy 仅从正文中抓取文本,但还没有任何运气.

I am trying to scrape the text only from body using python Scrapy, but haven't had any luck yet.

希望一些学者能够帮助我从 标签中抓取所有文本.

Wishing some scholars might be able to help me here scraping all the text from the <body> tag.

推荐答案

Scrapy 使用 XPath 表示法来提取 HTML 文档的一部分.那么,您是否尝试过仅使用 /html/body 路径来提取 ?(假设它嵌套在 中).使用 //body 选择器可能更简单:

Scrapy uses XPath notation to extract parts of a HTML document. So, have you tried just using the /html/body path to extract <body>? (assuming it's nested in <html>). It might be even simpler to use the //body selector:

x.select("//body").extract()    # extract body

您可以在此处找到有关 Scrapy 提供的选择器的更多信息.

You can find more information about the selectors Scrapy provides here.

这篇关于仅 Scrapy 正文文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆