【问题标题】:Python scraping xpath get <a> with specific <span>Python 抓取 xpath 获取具有特定 <span> 的 <a>
【发布时间】:2016-11-22 12:57:44
【问题描述】:

我正在使用 Scrapy 从网站获取一些数据。 我有以下链接列表:

<li class="m-pagination__item">
<a href="?isin=IT0000072618&lang=it&page=9">10</a>
</li>
<li class="m-pagination__item">
<a href="?isin=IT0000072618&lang=it&page=1">
<span class="m-icon -pagination-right"></span>
</a>

我只想提取包含 span class="m-icon -pagination-right" 的 'a' 元素的 href 属性。

我一直在寻找一些 xpath 的示例,但我不是 xpath 专家,也找不到解决方案。

谢谢。

【问题讨论】:

    标签: python xpath scrapy


    【解决方案1】:
    //a[span/@class = 'm-icon -pagination-right']/@href
    

    【讨论】:

      【解决方案2】:

      带有 Scrapy 响应:

      response.css('span.m-icon').xpath('../@href')
      

      【讨论】:

        猜你喜欢
        • 2020-08-13
        • 2014-11-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多