0

I'm trying to scrape a website with Selenium, but I think it's blocking this access in many ways.

The error message shown is: "selenium.common.exceptions.NoSuchWindowException: Message: Browsing context has been discarded" but sometimes is shown an error saying that time for loading page had expired

Furthermore, Firefox is consuming a huge percent of CPU and Memory when loading this page.

I've already tried to change user-agent, or run it headlessly, but no results.

Below is the code:

from selenium import webdriver
browser = webdriver.Firefox()
browser.get('https://www.bet365.com/#/HO/')
matches = browser.find_elements_by_class_name('him-Fixture')
browser.quit()

Any tips to bypass it ?

Maradei
  • 1
  • 2
  • if page uses JavaScript to add/display data then this JavaScript needs few (milli)seconds to do it. Selenium doesn't know what JavaScript is doing and it doesn't wait for JavaScript - so you may have to do it on your own with `time.sleep`. Or using [waits](https://selenium-python.readthedocs.io/waits.html) – furas Apr 29 '21 at 04:47

1 Answers1

1

Sometimes browsers loading late . So you add time.sleep() function in you code.

Example :

from selenium import webdriver
import time
browser = webdriver.Firefox()
browser.get('https://www.bet365.com/#/HO/')
time.sleep(5)
matches = browser.find_elements_by_class_name('him-Fixture')
browser.quit()
eminaruk
  • 60
  • 5
  • I tried it, but now it shows this error: selenium.common.exceptions.WebDriverException: Message: Failed to decode response from marionette – Maradei Apr 29 '21 at 22:52
  • This answer may help you : https://stackoverflow.com/a/55206440/14838504 – eminaruk Apr 30 '21 at 01:59