Scraping JS rendered page using Requests_HTML is not working as expected

Aftab

I am working on Scraping a JS rendered page ( https://www.flipkart.com/search?q=Acer+Laptops ). In this page the product images are being loaded dynamically. The pre-rendered SRC values for these images is

//img1a.flixcart.com/www/linchpin/fk-cp-zion/img/placeholder_9951d0.svg

After rendering, the SRC should be something like this

https://rukminim1.flixcart.com/image/312/312/kcp4osw0/computer/f/w/d/acer-na-thin-and-light-laptop-original-imaftrdmuyxq5nrf.jpeg?q=70

Using requests_html I can get the SRC values BUT it is only working for the first few images at the top. Please help me out here? My code :-

res = session.get("https://www.flipkart.com/search?q=Acer+Laptops")
res.html.render()
all_results = res.html.find('#container > div > div.t-0M7P._2doH3V > div._3e7xtJ > div._1HmYoV.hCUpcT > div:nth-child(2)', first=True) #Container for all the results
items = all_results.find('._1UoZlX') # Container for each product being displayed
for item in items:
   item_image = item.find('div._3BTv9X img', first=True).attrs.get('src')
   print(item_image)

Output:-

https://rukminim1.flixcart.com/image/312/312/kamtsi80/computer/m/8/y/acer-na-gaming-laptop-original-imafs5prytwgrcyf.jpeg?q=70
https://rukminim1.flixcart.com/image/312/312/kcp4osw0/computer/f/w/d/acer-na-thin-and-light-laptop-original-imaftrdmuyxq5nrf.jpeg?q=70
//img1a.flixcart.com/www/linchpin/fk-cp-zion/img/placeholder_9951d0.svg
//img1a.flixcart.com/www/linchpin/fk-cp-zion/img/placeholder_9951d0.svg

As you can see the first two images are loaded, the rest are not. Thank you all in advance!

Aftab

I found the solution, as the images were lazily loaded I had to use "scrolldown" and "sleep" parameters in the "render()" function. Find the code below:

res = session.get("https://www.flipkart.com/search?q=Acer+Laptops")
res.html.render(scrolldown=20, sleep=.1)
all_results = res.html.find('#container > div > div.t-0M7P._2doH3V > div._3e7xtJ > div._1HmYoV.hCUpcT > div:nth-child(2)', first=True) #Container for all the results
items = all_results.find('._1UoZlX') # Container for each product being displayed
for item in items:
   item_image = item.find('div._3BTv9X img', first=True).attrs.get('src')
   print(item_image)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Scraping javascript rendered HTML page in python

From Dev

Scraping elements rendered using React JS with BeautifulSoup

From Dev

Scraping a JavaScript rendered page

From Dev

How to wait to page to fully load using requests_html

From Dev

How to bypass AKAMAI bot detection for data scraping using requests_html, Beautiful Soup

From Dev

Get rendered page using JS or JQuery

From Dev

Using 'requests_html' with 'FastAPI'

From Dev

requests_html render scrolldown, script not working

From Dev

Scraping html page using preg_match

From Dev

Using Node.js to render data in pug - no data on rendered page

From Dev

Any way to scrape a JS Rendered page without using executables in Python?

From Dev

Web scraping for a javascript rendered website using selenium

From Dev

How to get last element when scraping with requests_html

From Dev

how to click on javascript using requests_html

From Dev

Scraping Dynamic page with Requests

From Dev

How to know HTML page needs to be rendered by JS compiler?

From Dev

python web scraping post form data using requests not working

From Dev

Trouble scraping all the follower names from a profile page using requests

From Dev

Serving REACT component using express is not working (just html file is rendered)

From Dev

Get rendered html wiki page using the GitHub API

From Dev

How to use rendered data using jinja in rendered template but without showing it in html page?

From Dev

HTML parsing not working as expected using BeautifulSoup

From Dev

Having issue scraping the html from certain websites, must enable JS and cookies enables? Using requests and bs4 for the scraping

From Dev

JS code not working as expected

From Dev

scraping content using selenium not working

From Dev

Scraping wiki page using beautifulsoup

From Dev

Web scraping with requests not working correctly

From Dev

Page Pagination/Scraping with Requests/BeautifulSoup

From Dev

Call a js function on an html snippet rendered using ngBindHtml

Related Related

  1. 1

    Scraping javascript rendered HTML page in python

  2. 2

    Scraping elements rendered using React JS with BeautifulSoup

  3. 3

    Scraping a JavaScript rendered page

  4. 4

    How to wait to page to fully load using requests_html

  5. 5

    How to bypass AKAMAI bot detection for data scraping using requests_html, Beautiful Soup

  6. 6

    Get rendered page using JS or JQuery

  7. 7

    Using 'requests_html' with 'FastAPI'

  8. 8

    requests_html render scrolldown, script not working

  9. 9

    Scraping html page using preg_match

  10. 10

    Using Node.js to render data in pug - no data on rendered page

  11. 11

    Any way to scrape a JS Rendered page without using executables in Python?

  12. 12

    Web scraping for a javascript rendered website using selenium

  13. 13

    How to get last element when scraping with requests_html

  14. 14

    how to click on javascript using requests_html

  15. 15

    Scraping Dynamic page with Requests

  16. 16

    How to know HTML page needs to be rendered by JS compiler?

  17. 17

    python web scraping post form data using requests not working

  18. 18

    Trouble scraping all the follower names from a profile page using requests

  19. 19

    Serving REACT component using express is not working (just html file is rendered)

  20. 20

    Get rendered html wiki page using the GitHub API

  21. 21

    How to use rendered data using jinja in rendered template but without showing it in html page?

  22. 22

    HTML parsing not working as expected using BeautifulSoup

  23. 23

    Having issue scraping the html from certain websites, must enable JS and cookies enables? Using requests and bs4 for the scraping

  24. 24

    JS code not working as expected

  25. 25

    scraping content using selenium not working

  26. 26

    Scraping wiki page using beautifulsoup

  27. 27

    Web scraping with requests not working correctly

  28. 28

    Page Pagination/Scraping with Requests/BeautifulSoup

  29. 29

    Call a js function on an html snippet rendered using ngBindHtml

HotTag

Archive