你好,我只是有一个关于连接错误的问题。因此,我正在运行该机器人,并且能够运行它的多个实例。当我这样做时,某些浏览器(无特定顺序或模式)会出现“连接错误”。这需要一些时间,也许这些连接错误会自行修复。我还记得在firefox上浏览时在后台运行机器人,尝试加载视频时遇到连接错误。那么有人知道geckodriver是怎么回事吗?编辑:网站已删除,如果您需要,可以提供。
from selenium import webdriver
from selenium.common.exceptions import InvalidElementStateException
from selenium.common.exceptions import UnexpectedAlertPresentException
import time, os, requests
from time import sleep
interest = input("Enter the interests seperate by a comma ")
msg1 = input("Enter your first message (1/4) >> ")
msg2 = input("Enter your second message (2/4) >> ")
msg3 = input("Enter your third message (3/4) >> ")
msg4 = input("Enter your fourth message (4/4) >> ")
driver = webdriver.Firefox()
def main():
try:
driver.get('REMOVED')
time.sleep(2)
driver.find_element_by_xpath('//textarea[@rows="3"]').clear()
message = driver.find_element_by_xpath('//textarea[@rows="3"]')
time.sleep(1)
message.send_keys(msg1)
send = driver.find_element_by_xpath('//button[@class="sendbtn"]')
send.click()
time.sleep(6)
message.send_keys(msg2)
send = driver.find_element_by_xpath('//button[@class="sendbtn"]')
send.click()
time.sleep(10)
message.send_keys(msg3)
send = driver.find_element_by_xpath('//button[@class="sendbtn"]')
send.click()
time.sleep(25)
message.send_keys(msg4)
send = driver.find_element_by_xpath('//button[@class="sendbtn"]')
send.click()
disconnect = driver.find_element_by_xpath('//button[@class="disconnectbtn"]')
disconnect.click()
disconnect = driver.find_element_by_xpath('//button[@class="disconnectbtn"]')
disconnect.click()
disconnect = driver.find_element_by_xpath('//button[@class="disconnectbtn"]')
disconnect.click()
except (InvalidElementStateException, UnexpectedAlertPresentException):
main2()
def main2():
try:
driver.get('REMOVED')
interest1 = driver.find_element_by_xpath('//input[@class="newtopicinput"]')
interest1.send_keys(interest)
btn = driver.find_element_by_id("textbtn")
btn.click()
time.sleep(5)
driver.find_element_by_xpath('//textarea[@rows="3"]').clear()
message = driver.find_element_by_xpath('//textarea[@rows="3"]')
time.sleep(1)
message.send_keys(msg1)
send = driver.find_element_by_xpath('//button[@class="sendbtn"]')
send.click()
time.sleep(6)
message.send_keys(msg2)
send.click()
time.sleep(10)
message.send_keys(msg3)
send.click()
time.sleep(25)
message.send_keys(msg4)
send.click()
send.click()
disconnect = driver.find_element_by_xpath('//button[@class="disconnectbtn"]')
disconnect.click()
except (InvalidElementStateException,UnexpectedAlertPresentException) :
disconnect = driver.find_element_by_xpath('//button[@class="disconnectbtn"]')
disconnect.click()
else:
main2()
while True:
try:
main2()
except (InvalidElementStateException,UnexpectedAlertPresentException) :
main()