使用Selenium和Python时Chrome打开网站并立即关闭

67up9zun  于 2023-03-06  发布在  Go
关注(0)|答案(1)|浏览(188)

Chrome版本:110.0.5481.104
Chrome驱动程序版本:110.0.5481.77

  • 从我所听到的版本的最后一位数字并不重要。*

它只是一个简单的代码:-

from selenium import webdriver
import os
os.environ['PATH'] =r"C:/Users/xxxx/Desktop/xxxx/Selenium/chromedriver_win32/chromedriver.exe"
driver=webdriver.Chrome()
driver.get("https://phptravels.com/demo/")

Chrome打开显示网站,然后立即关闭。如果版本是问题所在,请告知我应该从哪个版本下载,因为没有以104结尾的版本。
还有一些可能值得一提的事情... VS代码在终端显示了一个奇怪的错误:

USB: usb_device_handle_win.cc:1046 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)

感谢您的帮助将不胜感激。

xj3cbfub

xj3cbfub1#

你的程序在第5行结束了, selenium 元素也结束了。
尝试在末尾添加一个input(),以便程序在退出之前等待用户输入。
更好:

# It doesn't wait for user input but
# will close on Ctrl+C
while True:
    try:
        time.sleep(1);
    except KeyboardInterrupt:
        break;

相关问题