'Python Selenium stuck after page "loaded"
I'm using these options with chrome version 99.0.4844.82:
chrome_options = Options()
chrome_options.page_load_strategy = 'eager'
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-extensions')
prefs = {"profile.managed_default_content_settings.images": 2}
chrome_options.add_experimental_option("prefs", prefs)
driver = webdriver.Chrome('test_shit/chromedriver', chrome_options=chrome_options)
I tried page_load_strategy
with all arguments, none
just completely breaks my script
The problem in my code is in this part
try:
driver.set_page_load_timeout(30)
driver.get(url)
except:
print('DOESNT WORK')
continue
print('loaded url')
title = driver.title.replace(',,', '"').replace('„', '"')
print('got the title')
text = driver.find_element_by_xpath("/html/body").text
print('got the text')
It just gets stuck after driver.get(url)
, the print('loaded url')
never goes through.
I haven't encountered this problem until I tried to scrape Hindi websites, specifically these:
https://www.abplive.com/states/delhi-ncr/delhi-transport-department-to-redesign-ten-dangerous-streches-with-the-help-of-iit-delhi-soon-2052577
https://www.tv9hindi.com/india/40-percent-fatal-accidents-due-to-rear-end-collisions-findings-of-audit-report-by-ministry-of-road-and-transport-935425.html
https://hindi.news18.com/tag/road-accident/
It is very weird as sometimes it works, but most of the time it gets stuck on one.
To be clear: the text loads, it's there, even the favicon loads, the script just gets stuck.
I have been trying to solve this for hours, if anybody has any idea how to stop this I would be very greatful.
Solution 1:[1]
So, I finally managed to solve it. The problem was that I had a time.wait(1)
at the end of my code, I just removed it from there and put time.wait(3)
before driver.get(url)
.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Andrei Cristian TUDOR |