Reputation: 23
<a class="tab-link"> hoho </a>
<a class="tab-link" href="screener.ashx?v=110&s=ta_topgainers&r=41"><b>next</b></a>
<a class="tab-link"> hohaao </a>
I'm working on the scrapy how can I grap the href attribute value based on the content "next" in xpath?
Upvotes: 1
Views: 1867
Reputation: 473893
Check the b
element's text inside this way:
//a[b = "next"]/@href
Demo from the Scrapy Shell:
$ cat index.html
<div>
<a class="tab-link"> hoho </a>
<a class="tab-link" href="screener.ashx?v=110&s=ta_topgainers&r=41"><b>next</b></a>
<a class="tab-link"> hohaao </a>
</div>
$ scrapy shell file:////path/to/index.html
>>> response.xpath('//a[b = "next"]/@href').extract_first()
u'screener.ashx?v=110&s=ta_topgainers&r=41'
Upvotes: 1