我尝试运行这段代码:
cd
sudo apt-get -y install firefox
cd
wget https://github.com/mozilla/geckodriver/releases/download/v0.26.0/geckodriver-v0.26.0-linux64.tar.gz
tar xzf geckodriver-v0.25.0-linux64.tar.gz
sudo mv geckodriver /usr/bin/geckodriver
但我收到以下错误:
>>> cd
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'cd' is not defined
>>> sudo apt-get -y install firefox
File "<stdin>", line 1
sudo apt-get -y install firefox
^
SyntaxError: invalid syntax
>>> cd
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'cd' is not defined
>>> wget https://github.com/mozilla/geckodriver/releases/download/v0.26.0/geckodriver-v0.26.0-linux64.tar.gz
File "<stdin>", line 1
wget https://github.com/mozilla/geckodriver/releases/download/v0.26.0/geckodriver-v0.26.0-linux64.tar.gz
^
SyntaxError: invalid syntax
>>> tar xzf geckodriver-v0.25.0-linux64.tar.gz
File "<stdin>", line 1
tar xzf geckodriver-v0.25.0-linux64.tar.gz
^
SyntaxError: invalid syntax
>>> sudo mv geckodriver /usr/bin/geckodriver
File "<stdin>", line 1
sudo mv geckodriver /usr/bin/geckodriver
^
SyntaxError: invalid syntax
答案1
看起来好像您正在使用 Python 解释器运行命令。您显示的命令将由bash
终端中的shell 等运行。它不是 Python 代码。
除了第二个代码cd
不会执行任何操作并且可以被删除之外,我无法对代码的有效性发表任何评论,并且tar
需要修改该命令使用的文件名以匹配使用wget
( geckodriver-v0.26.0-linux64.tar.gz
) 下载的文件。