我正在用Python和selenium做一个简单的网络爬虫。(在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)
我尝试了文件路径的各种格式,但似乎都返回了错误。文件路径的正确格式是什么?附注:我从文件资源管理器复制的文件地址也不起作用。
发布于 2017-07-14 23:59:58
这是你问题的答案:
在自动化脚本中没有用于复制/访问驱动程序可执行文件的Best Practice
,但是在我的Windows 8 Pro
机器上,通过Python 3.6.1
使用PyCharm IDE
,我明确提到了驱动程序可执行文件的绝对路径,以便我可以使用不同版本的不同驱动程序可执行文件以及不同的Mozilla Firefox
版本,如下所示:
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')
如果这回答了你的问题,请让我知道。
发布于 2017-07-14 12:57:12
地址应包含在引号中,如下所示。
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get("http://www.python.org")
https://stackoverflow.com/questions/45094157
复制相似问题