'Selenium disconnecting router

I've noticed recently my router keeps turning off, and now I figured it is related to my selenium code, it runs each 30 minutes in my PC and I noticed that everytime my router disconnects the script was in the same line, getting data from selenium, is there something I can do? I've been searching through the router settings about traffic/security since I thought my router might be understading it as an attack but can't find anything.

It doesn't happen every run of the script, but everytime it happens it was getting data. Here's the script:

options = Options()
options.add_argument("--headless")
driver = webdriver.Firefox(options=options)
driver.get('https://www.reuters.com/markets/')
time.sleep(2)
element = driver.find_element(By.CSS_SELECTOR, "html")
pageinv = element.get_attribute('innerHTML')
driver.quit()


Solution 1:[1]

This is not the perfect answer but there are some things i've done that managed this.

Apparently when you use selenium to access multiple sites with the same driver, and some of them are protected by cloudflare, it starts to analyze this as an attack, I've tested multiple stuff here, with screenshots after/before the cloudflare alert. So my solution was closing the driver for each different website, so far running for 3 days straight without any new disconnection, heres an example of part of the code. I also inserted some time.sleep between the connections, not sure if this affects anything but also trying not to pass as an attack. Heres part of the code, in my case Im acessing around 20 sites.

from selenium import webdriver
from selenium.webdriver.firefox.options import Options as optf
import time

options = optf()
options.add_argument("--headless")
options.add_argument("--disable-gpu")
try:
    print("URL REUTERS")
    driver = webdriver.Firefox(options=options)
    time.sleep(5)
    driver.get('https://www.reuters.com/markets/')
    time.sleep(5)
    element = driver.find_element(By.CSS_SELECTOR, "html")
    pagereum = element.get_attribute('innerHTML')
    driver.close()
    driver.quit()
except:
    print("Falha REUTERS")
    pass
time.sleep(5)
try:
    print("URL BBC")
    driver = webdriver.Firefox(options=options)
    time.sleep(5)
    driver.get('https://www.bbc.com/portuguese/topics/cvjp2jr0k9rt')
    time.sleep(5)
    element = driver.find_element(By.CSS_SELECTOR, "html")
    pagebbc = element.get_attribute('innerHTML')
    driver.close()
    driver.quit()
except:
    print("Falha BBC")
    pass
time.sleep(5)
driver.quit()

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 Capuccino