Pakshadow
Pakshadow

Reputation: 21

How to get href value from a link using its class name with CSS selector in scrapy?

<a class="a-link-normal a-text-normal" href="/Art-Dutch-Republic-1585-Everyman/dp/0297833693/ref=sr_1_1?keywords=9780297833697&amp;qid=1574351815&amp;sr=8-1"> <span class="a-size-medium a-color-base a-text-normal">Art of the Dutch Republic 1585 - 1718 (Everyman Art Library)</span> </a>

How to get Value of href using CSS selector or Xpath?

Upvotes: 1

Views: 1986

Answers (4)

Ali Tauseef Reza
Ali Tauseef Reza

Reputation: 53

You can achieve this by following selector

a.your_calss_name::attr(href)

Upvotes: 0

Ikram Khan Niazi
Ikram Khan Niazi

Reputation: 807

Try this response.css('.a-link-normal ::attr(href)').extract()

Upvotes: 0

Georgiy
Georgiy

Reputation: 3561

CSS selectors example:

links = response.css("a.a-link-normal.a-text-normal::attr(href)").extract()

Upvotes: 0

nicolas
nicolas

Reputation: 3280

Here is an example:

    def parse(self, response):
        # iterate over all href
        for href in response.xpath("//a[@class='class-name']/@href"):
            # extract href as a string
            url = href.extract()

Upvotes: 1

Related Questions