简体   繁体   中英

Xpath: how to get the text of <a> tag inside a <p> tag

I am trying to save information from some webs using scrapy what I have found one issue and I don't know how to fix it.

I'm trying to get all the text inside p tag, but my problem is that in some cases inside those tags there is no only text, there is sometimes some a tag and stops collecting the text when reachs that tag.

This is my Xpath expression, it's working properly wheren there are not a tags...

description=descriptionpath.xpath("span[@itemprop='description']/p/text()").extract()

Any help would be appreciated!

Thanks in advance!

Posting Pawel Miech's comment as an answer as it appears his comment has helped many of us thus far and contains the right answer:

Tack //text() on the end of the xpath to specify that text should be recursively extracted.

So your xpath would appear like this:

span[@itemprop='description']/p//text()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM