Python抓取xpath获取<a> with specific <span>

时间:2016-11-22 12:57:45

标签: python xpath scrapy

I'm using Scrapy to get some data from a website. I have the following list of links:

<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>

I want to extract the href attribute only of the 'a' element that contains the span class="m-icon -pagination-right".

I've been looking for some examples of xpath but I'm not an expert of xpath and I couldn't find a solution.

Thanks.

2 个答案:

答案 0 :(得分:1)

//a[span/@class = 'm-icon -pagination-right']/@href

答案 1 :(得分:1)

通过Scrapy回复:

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