Closed CathyChang1996 closed 5 years ago
My suggestion is you can add a for loop to give a range for the scroll times, like: scroll 100 times, you can adjust by your observation of how many articles there are.
for i in range(1,00):
...
browser.execute_script('window.scrollTo(0, document.body.scrollHeight);')
except:
Another way is to use while true
#condition here
while True:
try:
...
browser.execute_script('window.scrollTo(0, document.body.scrollHeight);')
except:
print(Error_Raise)
Problem solved! Thanks a lot!
Although the problem is solved, I leave an alternative solution here: https://github.com/hupili/python-for-data-and-media-communication/blob/master/scraper-examples/mafengwo-xhr.ipynb
Crawling by network trace analysis and XHR is also common. However, the analysis is case by case so we only briefly mentioned in the notes
Troubleshooting
Describe your environment
Describe your question
When I tried to scrape all the location names in a page, I found it should be with a infinite scrolling process to get all the information, how to make it happen?
The minimum code (snippet) to reproduce the issue