【发布时间】:2018-01-28 16:42:39
【问题描述】:
我是论坛的新手,但已搜索帖子以解决我的问题。
以下是我用来尝试进行故障排除的帖子: #1 #2 ~ 以及其他 Google 搜索结果。
我从 Windows 切换到 Linux Mint,但无法设置。总的来说,我对 Python/编程也很陌生,所以请耐心等待。
Linux Mint 安装了 Python2,但我已经用 Python3 完成了所有练习,所以我安装了 Python 3,这意味着我还必须安装 Python3 版本的 Selenium、Geckodriver 等才能运行我的练习脚本用于网页抓取。
当我运行我的代码时,它会按预期提示输入搜索词,但随后会引发以下错误:
Traceback (most recent call last):
File "/home/myName/Documents/Programming Misc/Python/craigslistSearch_linkGeneration_v02.py", line 15, in <module>
browser = webdriver.Firefox()
File "/usr/lib/python3/dist-packages/selenium/webdriver/firefox/webdriver.py", line 77, in __init__
self.binary, timeout),
File "/usr/lib/python3/dist-packages/selenium/webdriver/firefox/extension_connection.py", line 47, in __init__
self.profile.add_extension()
File "/usr/lib/python3/dist-packages/selenium/webdriver/firefox/firefox_profile.py", line 91, in add_extension
self._install_extension(extension)
File "/usr/lib/python3/dist-packages/selenium/webdriver/firefox/firefox_profile.py", line 251, in _install_extension
compressed_file = zipfile.ZipFile(addon, 'r')
File "/usr/lib/python3.5/zipfile.py", line 1009, in __init__
self.fp = io.open(file, filemode)
FileNotFoundError: [Errno 2] No such file or directory: '/usr/lib/firefoxdriver/webdriver.xpi'
这是有问题的代码:
from selenium import webdriver #To launch the browser (Firefox)
from selenium.webdriver.common.keys import Keys #To be able to send special keys (i.e., DOWN, UP, RIGHT, LEFT, TAB, HOME, etc.)
import time #To pause the program for x seconds
import string #To run string.replace()
import requests
#prompt the user to enter their desired search term
print('Please enter your search term')
searchTerm = input()
newSearchTerm = str.replace(searchTerm, ' ', '+')
#open browser and navigate to craigslist + user-defined search term(s)
browser = webdriver.Firefox()
type(browser)
searchURL = browser.get('https://seattle.craigslist.org/search/sss?query=' + newSearchTerm)
【问题讨论】:
标签: linux python-3.x selenium webdriver