我对python还是很陌生,现在,我目前正在通过Al Sweigart的“使用Python自动化无聊的东西”来学习python。
现在,我想使用webdriver打开Firefox。当我运行代码时:
getxxxExtra/getExtras
我没有错误。但是,运行后:
export default class Status extends Component {
constructor(props) {
super(props);
this.state = {
// some features
};
}
recheck = event => {
// some status check
}
componentDidMount() {
this.interval = setInterval(() => this.check(), 1000);
}
componentWillUnmount() {
clearInterval(this.interval);
}
render() {
return (
<div className="Status">
{/*... some status */}
</div>
);
}
}
我收到以下错误消息。
from selenium import webdriver
现在,我已经安装了geckodriver,并且一直在滚动浏览谷歌以查找解决方案。到目前为止,我已经尝试将geckodriver手动添加到/ usr / local / bin。我也尝试过跑步:
browswer=webdriver.Firefox()
在终端上。它建议我尝试覆盖geckodriver,因此brew在/usr/local/Cellar/geckodriver/0.21.0/bin/geckodriver上安装了geckodriver。
我跑了
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 76, in start
stdin=PIPE)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 1344, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'geckodriver': 'geckodriver'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
browswer=webdriver.Firefox()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py", line 160, in __init__
self.service.start()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 83, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
查看我的路径列表,以下是列表:
brew install geckodriver
所以我不知道为什么python告诉我geckodriver可执行文件必须已经在PATH中。
有人可以帮我吗?
答案 0 :(得分:0)
答案 1 :(得分:0)
我在Mac OS上遇到了与OP完全相同的问题。为我解决的是将geckodriver复制到python路径中。
特别是在终端机
which geckdriver
给出以下路径
/usr/local/bin/geckodriver
和
which python
为Python提供了路径
/Users/USERNAME/anaconda3/bin/python
然后我将geckodriver复制到python bin
cd /usr/local/bin/
cp geckodriver /Users/USERNAME/anaconda3/bin/
我能够从Python调用geckodriver。