jus*_*ing 4 python selenium google-chrome httpconnection selenium-chromedriver
我尝试编写一个简单的脚本,每小时检查一次网站,并在发现有空时向我发送电子邮件。
我认为每隔一小时执行此操作不会引发任何问题,但出现以下错误:
MaxRetryError: HTTPConnectionPool(host='127.0.0.1', port=60745): Max retries exceeded with url: /session/900f45d6c8c800f2a8ebcf43daa05b69/url (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fa42c261c10>: Failed to establish a new connection: [Errno 61] Connection refused'))
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
import schedule
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from notification import *
#script i have to send an email (works fine)
PATH = "mypath"
# i have the path where there drivers are
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--window-size=1920x1080")
# to not open the browser
driver = webdriver.Chrome(options=chrome_options, executable_path=PATH)
def get_stock():
driver.get("website i'm trying to check")
# access the website
search = driver.find_element_by_name("add")
# add is the name of the button i wanna check
result = search.is_enabled()
print(result)
driver.quit()
schedule.every().hour.do(get_stock)
# run the get_stock function every hour
c = 0
# initialize the loop
while c == 0:
schedule.run_pending()
c = get_stock()
# set the seed equal to the get_stock so that it stops once it becomes True
time.sleep(1)
print(get_stock())
email("Now there's a stock.")
#using my notification script to send the email
Run Code Online (Sandbox Code Playgroud)
我是初学者,所以任何帮助将不胜感激。
这个错误信息...
MaxRetryError: HTTPConnectionPool(host='127.0.0.1', port=60745): Max retries exceeded with url: /session/900f45d6c8c800f2a8ebcf43daa05b69/url (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fa42c261c10>: Failed to establish a new connection: [Errno 61] Connection refused'))
Run Code Online (Sandbox Code Playgroud)
...暗示ChromeDriver无法启动/生成/与浏览上下文(即Chrome 浏览器会话)通信。
此错误的根本原因可能是以下任一原因:
driver.close()driver.quit()确保这件事:
driver.quit()在tearDown(){}方法内调用以优雅地关闭和销毁WebDriver和Web Client实例。您可以在以下位置找到一些相关的详细讨论:
| 归档时间: |
|
| 查看次数: |
4319 次 |
| 最近记录: |