Pycharm selenium如何打开实际的webbroswer窗口(LINUX)



为第一篇帖子道歉,我是新来的STACK OVERFLOW。。。非常感谢你的帮助。。。我可以在不打开实际窗口的情况下运行它,不过我想看看它打开的实际页面。。。我。。-导入的os-确保网络驱动程序是最新的并且与当前版本匹配-在路径上。。(绝对和相对,甚至将驱动程序放在同一文件中

  • 尝试过Chrome和Firefox
  • checked chown是我并且是可执行的-当我键入chromedriver时,它将从单独的终端实例打开。-"whichchromedriver"显示/usr/bin/cromedriver(我用它作为路径。我有一个运行Ubuntu(POPos(的全新linux系统所有更新和升级。我不知道怎么了

来自硒导入网络驱动程序导入操作系统导入时间

options = webdriver.ChromeOptions()
options.add_argument('--headless') # Remove this if you want a selenium controlled browser window
options.add_argument('--ignore-certificate-errors')
user_agent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36'
options.add_argument('user-agent={0}'.format(user_agent))
preferences = {
"profile.default_content_settings.popups": 0,
"download.default_directory": os.getcwd() + os.path.sep,
"directory_upgrade": True
} # My own set of preferences, use what you want
options.add_experimental_option('prefs', preferences)
driver = webdriver.Chrome("/home/wprice/PycharmProjects/sele/chromedriver-Linux64", options=options) # Since I am using Windows
driver.get("HTTPS://GOOGLE.COM")
time.sleep(20)
driver.save_screenshot("test.png")
ERRORS:
/home/wprice/PycharmProjects/sele/bin/python /home/wprice/PycharmProjects/sele/sele.py
Traceback (most recent call last):
File "/home/wprice/PycharmProjects/sele/sele.py", line 18, in <module>
driver = webdriver.Chrome("/home/wprice/PycharmProjects/sele/chromedriver-Linux64", options=options) # Since I am using Windows
File "/home/wprice/PycharmProjects/sele/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
self.service.start()
File "/home/wprice/PycharmProjects/sele/lib/python3.8/site-packages/selenium/webdriver/common/service.py", line 98, in start
self.assert_process_still_running()
File "/home/wprice/PycharmProjects/sele/lib/python3.8/site-packages/selenium/webdriver/common/service.py", line 109, in assert_process_still_running
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: Service /home/wprice/PycharmProjects/sele/chromedriver-Linux64 unexpectedly exited. Status code was: 127


我们没有您的代码/堆栈跟踪,所以我猜这可能是我目前能想到的以下问题之一::

  1. 编辑器无法找到正确的web驱动程序路径
  2. 您的Chrome网络驱动程序版本与安装的Chrome版本不匹配
  3. 初始化web驱动程序时出错

因此,基于此,您可以尝试此代码,只需将变量替换为正确的值,它可能会在中工作

options = webdriver.ChromeOptions()
options.add_argument('--headless') # Remove this if you want a selenium controlled browser window
options.add_argument('--ignore-certificate-errors')
user_agent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36'
options.add_argument('user-agent={0}'.format(user_agent))
preferences = {
"profile.default_content_settings.popups": 0,
"download.default_directory": os.getcwd() + os.path.sep,
"directory_upgrade": True
} # My own set of preferences, use what you want
options.add_experimental_option('prefs', preferences)
driver = webdriver.Chrome("CHROMEDRIVER.EXE_ABSOLUTE_PATH", options=options) # Since I am using Windows
driver.get("WEBSITE_TO_SCRAPE")
time.sleep(20)
driver.save_screenshot("test.png")

最新更新