[英]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. 我正在尝试使用scrapy来保存某些网站上的信息,但我发现了一个问题,但我不知道如何解决。
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. 我试图将所有文本都包含在p标签内,但是我的问题是,在某些情况下,这些标签内不仅只有文本,有时还有一些标签,当到达该标签时便停止收集文本。
This is my Xpath expression, it's working properly wheren there are not a tags... 这是我的Xpath表达式,在没有标签的地方它可以正常工作。
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: 张贴Pawel Miech的评论作为答案,因为到目前为止他的评论似乎已经帮助了我们许多人,并且包含了正确的答案:
Tack //text()
on the end of the xpath to specify that text should be recursively extracted. 在xpath的末尾添加
//text()
,以指定应递归提取文本。
So your xpath would appear like this: 因此,您的xpath将如下所示:
span[@itemprop='description']/p//text()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.