问题
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.
回答1:
Try it:
response.xpath('//body/node()/text()')
Or if you want the tags too:
response.xpath('//body/node()')
回答2:
Try
//body/(descendant::text() | following::text())
or
//body/descendant::text() | //body/following::text()
来源:https://stackoverflow.com/questions/31586271/scrapy-get-all-data-within-selector