24/7 Python selenium“;虽然是真的,但“是的。”;脚本可以';t执行驱动程序.get(“URL”)

24/7 Python selenium“;虽然是真的,但“是的。”;脚本可以';t执行驱动程序.get(“URL”),python,selenium,selenium-webdriver,selenium-chromedriver,pythonanywhere,Python,Selenium,Selenium Webdriver,Selenium Chromedriver,Pythonanywhere,这是一个奇怪的问题 我的脚本有一个,而True:脚本全天候运行。它总是每隔sleep(55)秒点击print('False'),一旦current\u time在指定时间之间,它就会调用driver.get(“URL”)并在网站上执行一些操作 但有时它会遇到一个错误,无法打开driver.get('https://www.instagram.com/accounts/login/?source=auth_switcher)并在下面打印错误 Traceback (most recent call

这是一个奇怪的问题

我的脚本有一个
,而True:
脚本全天候运行。它总是每隔
sleep(55)
秒点击
print('False')
,一旦
current\u time
在指定时间之间,它就会调用
driver.get(“URL”)
并在网站上执行一些操作

但有时它会遇到一个错误,无法打开
driver.get('https://www.instagram.com/accounts/login/?source=auth_switcher)
并在下面打印错误

Traceback (most recent call last):
  File "/home/matt/insta/users/nycforest/lcf.py", line 254, in <module>
    lcf_time(input_begin_time,input_end_time,input_begin_time2,input_end_time2)
  File "/home/matt/insta/users/nycforest/lcf.py", line 241, in lcf_time
    login()
  File "/home/matt/insta/users/nycforest/lcf.py", line 40, in login
    driver.get('https://www.instagram.com/accounts/login/?source=auth_switcher')
  File "/home/matt/.local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 333, in get
    self.execute(Command.GET, {'url': url})
  File "/home/matt/.local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/home/matt/.local/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: timeout
  (Session info: headless chrome=78.0.3904.70)
  (Driver info: chromedriver=2.42.591071 (0b695ff80972cc1a65a5cd643186d2ae582cd4ac),platform=Linux 5.4.0-1020-aws x86_64)
奇怪的是:我有几个不同的脚本运行完全相同的脚本,具有不同的变量,有些脚本很好,而另一些脚本在60%的时间里一直运行这个脚本。我需要一种更可靠的方法来
driver.get(“URL”)
24/7


这是兼容性问题吗?我做错了什么吗?

您可以只使用Python或“curl”命令,而不是使用Selenium


通过这种方式,您可以创建一个bash/shell脚本,在需要时触发该脚本,而无需保持IDE的运行。

您可以只使用Python或“curl”命令,而不使用Selenium


通过这种方式,您可以创建一个bash/shell脚本,在需要时触发脚本,而无需保持IDE运行。

我有除
login()以外的其他函数,需要使用Selenium的webdriverI;我有除
login()以外的其他函数
需要使用Selenium的webdriverIs,您是否可能受到Instagram的费率限制?一般来说,他们对机器人的看法相当模糊,因此如果你一直用脚本访问他们的网站,他们可能会周期性地没有响应。你是否可能受到Instagram的速率限制?一般来说,他们对机器人的看法相当模糊,所以如果你一直用脚本访问他们的站点,他们可能会周期性地没有响应。
from pyvirtualdisplay import Display
from datetime import datetime, time
from itertools import islice
from random import randint
from time import sleep
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import NoSuchElementException

input_begin_time = time(18,40)
input_end_time = time(18,50)
input_begin_time2 = time(21,20)
input_end_time2 = time(21,30)

opts = webdriver.ChromeOptions()
opts.add_argument('--headless')
opts.add_argument('--disable-gpu')
opts.add_argument('--no-sandbox')
opts.add_argument('--disable-dev-shm-usage')
opts.add_argument('--enable-features=NetworkService,NetworkServiceInProcess')



def login():
    sleep(2)
    driver.get('https://www.instagram.com/accounts/login/?source=auth_switcher')
    driver.set_page_load_timeout(20)
    sleep(3)

    input_username = driver.find_element_by_name('username').send_keys(username)
    input_password = driver.find_element_by_name('password').send_keys(password)

    button_login = driver.find_element_by_css_selector('#loginForm > div > div:nth-child(3) > button')
    button_login.click()

# def other_functions()

driver = webdriver.Chrome(options=opts)

def lcf_time(time_begin1, time_end1, time_begin2, time_end2, curren_time=None):
    current_time = datetime.now().time()
    if time_begin1 < current_time < time_end1 or time_begin2 < current_time < time_end2:
        login()
        # other_functions()
        driver.close()
    else:
        print("False")


while True:
    lcf_time(input_begin_time,input_end_time,input_begin_time2,input_end_time2)
    sleep(55)