Scrapy - 获取选择器中的所有数据 [英] Scrapy - Get all data within selector
本文介绍了Scrapy - 获取选择器中的所有数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我的响应中有一些 HTML 如下所示:
正文<div>div 文本
如果我做 response.xpath('//body/text()').extract()
我只会得到 [Body text]
我想在 中获取所有内容,包括标签,即整个内容:
正文<div>div 文本
我怎样才能做到这一点?
谢谢.
解决方案
试试看:
response.xpath('//body/node()/text()')
或者如果你也想要标签:
response.xpath('//body/node()')
If I have some HTML in the response that looks like:
<body>
Body text
<div>
Div text
</div>
</body>
If I do response.xpath('//body/text()').extract()
I will only get [Body text]
I want to get everything inside <body>
including the tags i.e. this whole thing:
Body text
<div>
Div text
</div>
How can I accomplish that?
Thank you.
解决方案
Try it:
response.xpath('//body/node()/text()')
Or if you want the tags too:
response.xpath('//body/node()')
这篇关于Scrapy - 获取选择器中的所有数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文