1

I was trying to scrape some data from flipkart.com using scrapy. I got everything other than going to the next page. first I tried using scrapy followed by selenium. actually, a class has 2links for the previous page and for the next page.

with scrapy: I am unable to fetch any result. I am getting the blank output.

with selenium: whenever I try to click on the next page it works fine from page 1 to page 2. but then instead of going on the 3rd page, it's coming back to the second page.

is there any other way to do this? how should I distinguish the URLs for the previous page and the next page?

4
  • please share your code Commented Feb 9, 2021 at 17:47
  • 1
    You can change the page number directly in the URL: https://www.flipkart.com/...&page=3. Commented Feb 9, 2021 at 17:48
  • I'd suggest changing the URL like @YevhenKuzmovych says (preferably using scrapy), since the xpath of elements might change everytime you click next. The xpath may also vary depending on the products category Commented Feb 9, 2021 at 17:52
  • thanks @YevhenKuzmovych It is working... Commented Feb 11, 2021 at 7:18

1 Answer 1

1

just append [-1] so that driver only fetches the last occurring result for the given class/id for flipkart the code is as follows

driver.find_elements_by_xpath('//a[@class="_1LKTO3"]')[-1].click()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.