Reputation: 115
the data i want to scrape is layed out like this:
<div class="ads__unit">
<div>2001</div>
<div>10 000</div>
<div>200 000</div>
</div>
There are multiple items with this div class. Im trying to scrape the first div within the add_unit div for every item. Is there a way i can select the first div?
Upvotes: 2
Views: 573
Reputation: 716
XPATH Selector:
//div[@class="ads__unit"]/div[1]/text()
CSS Selector:
div.ads__unit div:first-child
CSS Selector (Scrapy):
div.ads__unit div:first-child::text
Upvotes: 2
Reputation: 976
You also can use get()
method to get first of element of list in any selector:
response.xpath('//div[@class="ads__unit"]/div/text()').get()
or index nth the element of list
response.xpath('//div[@class="ads__unit"]/div/text()').getall()[n]
Upvotes: 0
Reputation: 115
Ive found that you can use
nth-child(n)
to select the differnt div in the same class
Upvotes: 0