Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何从嵌套的div中获取XPath值_Python_Xpath_Web Scraping_Scrapy - Fatal编程技术网

Python 如何从嵌套的div中获取XPath值

Python 如何从嵌套的div中获取XPath值,python,xpath,web-scraping,scrapy,Python,Xpath,Web Scraping,Scrapy,如何通过向xpath提供密钥“安装”来获得值5000+ <div class="hAyfc"> <div class="BgcNfc">Installs</div> <span class="htlgb"> <div><span class="htlgb">5,000+</span></div> </span>

如何通过向xpath提供密钥“安装”来获得值5000+

      <div class="hAyfc">
        <div class="BgcNfc">Installs</div>
        <span class="htlgb">
          <div><span class="htlgb">5,000+</span></div>
        </span>
      </div>

安装
5,000+
我尝试了这个响应。xpath(“//span/div/span/text()”).extract()但它给出了所有文本

有人能帮我吗?

试试这个:

response.xpath('./div/span[@class="htlgb"]/text()').extract()

我试过这个,它成功了:

response.xpath('//div[./div/text()="Installs"]/span/div/span/text()').extract_first()

它搜索具有
text()=“Installs”
子级的
div
,然后搜索包含您请求的值的
span

您所说的“…给出所有文本”是什么意思?您期望的和当前的输出是什么?还可以尝试
//div[.=“Installs”]/以下同级::span/div/span/text()
@anderson它对我有用。谢谢,我不想使用这个课程,因为它可能会改变。当然好的,你能给我网站吗,我会相应地更新我的答案。