I am trying to scrape this page: https://www.jomashop.com/watches.html?dir=desc&order=bestsellers
my current code to get a list of the product urls is:
def start_requests(self):
yield scrapy.Request(
url=self.start_url,
callback=self.parse_product_url,
headers=self.headers,
dont_filter=True,
meta={"page": 1}
)
def parse_product_url(self, response):
if response.status in self.handle_httpstatus_list:
time.sleep(5)
yield response.request
else:
meta_product = response.meta
meta_product["rank"] = 0
meta_product["category_url"] = response.url
product_urls = response.xpath("//a[@class='productName-link']/a/@href").extract()
but the product_urls is consistently returning empty. I am not well versed in the syntax of xpath, so I think there is a problem with how I have worded it. Any help to get the product url is appreciated! thank you!
I have also tried:
response.xpath("//div[@class='product-details']/h2[@class='productName-link']/text()")
response.xpath("//a[@class='productName-link']/a/@href").extract()
response.xpath("//*[contains(@class, 'product-details')]/a/@href").extract()
response.xpath("//*[contains(@class, 'productName-link')]/a/@href").extract()
response.xpath("//*[@id='product-list-wrapper']/ul/li[4]/div/div[2]/h2/a").extract()
response.xpath("/html/body/div[1]/div/main/div[1]/div[2]/div[2]/div[2]/ul/li[4]/div/div[2]/h2/a").extract()
I feel like I am so close, but none of these seem to be working.