【问题标题】:What is the equivalent of this BeautifulSoup expression in Xpath?Xpath 中这个 BeautifulSoup 表达式的等价物是什么?
【发布时间】:2020-08-12 06:43:17
【问题描述】:

我正在尝试使用scrapy 和BeautifulSoup 来抓取这个link,但由于某种原因,BeautifulSoup 不能在蜘蛛中工作,它只能在scrapy shell 中工作。我知道这听起来很傻,但是,如何将其转换为 Xpath?

soup.find('li', {'class': 'at-listing__list-icons_location'})

我试过了

response.xpath('//li[contains(text(),"at-listing__list icons_location")]/../descendant::text()').extract()

请参阅my other question,其中包含了我尝试使用 splash 和 BeautifulSoup 使事情正常运行的日志,但到目前为止所有尝试都失败了。

【问题讨论】:

    标签: xpath beautifulsoup scrapy


    【解决方案1】:

    我想您想获得 3 个值“Süddeutschland”、“Feste Anstellung”和“Vollzeit”? 在这种情况下,下面的 xpath 对我有用:

    response.xpath('//*[has-class("at-listing__list-icons_location")]/../descendant::text()').extract()
    

    我认为您的 xpath 中的问题是您试图在文本中查找值 'at-listing__list icons_location',而不是类。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-16
      • 2023-04-05
      • 1970-01-01
      • 2010-11-05
      • 1970-01-01
      • 2011-04-12
      • 1970-01-01
      • 2011-03-19
      相关资源
      最近更新 更多