如何解决无法访问Python Selenium Chrome
我的脚本在打开后的头几天运行良好。但通常不能维持超过3天。打开浏览器并进入whatapps页面并关闭它时,脚本开始循环。我试图杀死所有的Chrome,然后再运行,但似乎不是问题所在。我该怎么解决?
这是我的剧本
def sdWhatApps_noteice(name,msg):
run = False
while not run:
try:
subprocess.call("TASKKILL /f /IM CHROME.EXE")
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option("excludeSwitches",['enable-automation'])
chrome_options.add_argument(r'user-data-dir=C:\Users\xxxxx\AppData\Local\Google\Chrome\User Data')
driver = webdriver.Chrome(ChromeDriverManager().install(),options=chrome_options)
try:
driver.get('https://web.whatsapp.com/')
time.sleep(30)
name = name
msg = msg
time.sleep(10)
user = driver.find_element_by_xpath('//span[@title = "{}"]'.format(name))
user.click()
msg_box = driver.find_element_by_xpath('//div[@class="_3uMse"]')
for part in msg.split('\n'):
#msg_box.send_keys(part)
print(part)
ActionChains(driver).send_keys(part).perform()
ActionChains(driver).key_down(Keys.SHIFT).key_down(Keys.ENTER).key_up(Keys.SHIFT).key_up(Keys.ENTER).perform()
#ActionChains(driver).send_keys(Keys.RETURN).perform()
time.sleep(randint(5,10))
button = driver.find_element_by_xpath('//button[@class="_1U1xa"]')
button.click()
time.sleep(5)
driver.quit()
run = True
except Exception as e:
print("Failed " + str(e))
driver.quit()
continue
except Exception as e:
print("Failed " + str(e))
continue
我的错误消息如下
[WDM] - Current google-chrome version is 86.0.4240
INFO:WDM:Current google-chrome version is 86.0.4240
[WDM] - Get LATEST driver version for 86.0.4240
INFO:WDM:Get LATEST driver version for 86.0.4240
[WDM] - Driver [C:\Users\Administrator\.wdm\drivers\chromedriver\win32\86.0.4240.22\chromedriver.exe] found in cache
INFO:WDM:Driver [C:\Users\Administrator\.wdm\drivers\chromedriver\win32\86.0.4240.22\chromedriver.exe] found in cache
Failed Message: session not created
from chrome not reachable
(Session info: chrome=86.0.4240.111)
SUCCESS: The process "chrome.exe" with PID 4124 has been terminated.
SUCCESS: The process "chrome.exe" with PID 4940 has been terminated.
SUCCESS: The process "chrome.exe" with PID 2688 has been terminated.
SUCCESS: The process "chrome.exe" with PID 6424 has been terminated.
SUCCESS: The process "chrome.exe" with PID 4092 has been terminated.
SUCCESS: The process "chrome.exe" with PID 6856 has been terminated.
SUCCESS: The process "chrome.exe" with PID 1756 has been terminated.
[WDM] - Current google-chrome version is 86.0.4240
INFO:WDM:Current google-chrome version is 86.0.4240
[WDM] - Get LATEST driver version for 86.0.4240
INFO:WDM:Get LATEST driver version for 86.0.4240
[WDM] - Driver [C:\Users\Administrator\.wdm\drivers\chromedriver\win32\86.0.4240.22\chromedriver.exe] found in cache
INFO:WDM:Driver [C:\Users\Administrator\.wdm\drivers\chromedriver\win32\86.0.4240.22\chromedriver.exe] found in cache
2020-10-30 07:59:00.056340
2020-10-30 07:59:00.237358
Failed Message: chrome not reachable
(Session info: chrome=86.0.4240.111)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。