I am trying to scrape the following website:
I am successful in scraping the first page, but I have trouble going to the next pages. There are two reasons for this:
When inspecting the
next_pagebutton I don't get a relative or an absolute URL. Instead I getJavaScript:getPage(2)which I can't use to follow linksThe next page button link can be accessed via
(//table[@class='tbl_pagination']//a//@href)[11]when being on the first page, but from the 2nd page and onwards, the next page button is the 12th item, i.e.(//table[@class='tbl_pagination']//a//@href)[12]
So ultimately my question is, how do I effectively go to ALL the subsequent pages and scrape the data.
This is probably very simple to solve, but I am a beginner in web scraping so any feedback is appreciated. Please see below my code.
Thanks for your help.
**
import scrapy
from scrapy_selenium import SeleniumRequest
class WinesSpider(scrapy.Spider):
name = 'wines'
def start_requests(self):
yield SeleniumRequest(
url='https://www.getwines.com/category_Wine',
wait_time=3,
callback=self.parse
)
def parse(self, response):
products = response.xpath("(//div[@class='layMain']//tbody)[5]/tr ")
for product in products:
yield {
'product_name':
product.xpath(".//a[@class='Srch-producttitle']/text()").get(),
'product_link':
product.xpath(".//a[@class='Srch-producttitle']/@href").get(),
'product_actual_price':
product.xpath(".//td//td[3]//td/span[2]/text()").get(),
'product_price_onsale':
product.xpath(".//td//td[3]//td/span[4]/text()").get()
}
#next_page = response.xpath("(//table[@class='tbl_pagination']//a//@href)[11]").get()
#if next_page:
# absolute_url = f"'https://www.getwines.com/category_Wine"**