Reputation: 580
I am trying to extract the link of Anchor Tag using Xpath
URL
<a class="text size-1x-small font-accent color-brand all-caps"
href="http://time.com/section/business"
data-reactid="199">
Business
</a>
Code
item["category"] = str(
response.xpath(
'//a[@class="text size-1x-small font-accent color-brand all-caps"]/text()'
).extract()
)
And the python function
def parseSave(self, response):
item = NYtimesItem()
item["category"] = response.xpath(
'//a[@class="text size-1x-small font-accent color-brand all-caps"]/text()'
).extract()
yield item
Please tell me what I am doing wrong The expected output would be the text of Anchor Tag. e.g Business
Upvotes: 1
Views: 929
Reputation: 3740
/text()
is meant to get the element's inner text. To extract the href attribute use /@href
instead.
Here is a handy xpath cheatsheet
Upvotes: 1