如何在Windows 10中使用python编写Selenium Webdriver路径地址? [英] How to write Selenium Webdriver path address with python in Windows 10?
问题描述
我正在使用带有硒的Python制作一个简单的Web搜寻器. (在PyCharm窗口10上运行)
I'm making a simple web crawler using Python with selenium. (Running on PyCharm Window 10)
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get(http://www.python.org)
我为文件Path尝试了多种格式,但是它们似乎都返回错误. 文件路径的正确格式是什么? P.S.我从文件资源管理器复制的文件地址也不起作用.
I tried various formats for the file Path but all of them seem to return error. What would be the correct format for the file Path? P.S. File address I copied off from File Explorer doesn't work either.
推荐答案
以下是您的问题的答案:
Here is the Answer to your Question:
在自动化脚本中没有Best Practice
可以复制/访问驱动程序可执行文件,但是在我的Windows 8 Pro
机器上,其中PyCharm IDE
到Python 3.6.1
,我明确提到了驱动程序可执行文件的绝对路径,这样我就可以使用不同版本的不同驱动程序可执行文件以及不同的Mozilla Firefox
版本,如下所示:
There is no Best Practice
to copy/access the driver executable in the Automation Script but on my Windows 8 Pro
machine with PyCharm IDE
through Python 3.6.1
, I explicitly mention the absolute path of the driver executable so that I can work with different versions of different driver executable as well as different Mozilla Firefox
versions as follows:
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
binary = FirefoxBinary('C:\\Program Files\\Mozilla Firefox\\firefox.exe')
caps = DesiredCapabilities().FIREFOX
caps["marionette"] = True
driver = webdriver.Firefox(capabilities=caps, firefox_binary=binary, executable_path="C:\\Utility\\BrowserDrivers\\geckodriver.exe")
driver.get('https://stackoverflow.com')
让我知道这是否回答了您的问题.
Let me know if this Answers your Question.
这篇关于如何在Windows 10中使用python编写Selenium Webdriver路径地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!