最近要用爬虫爬一些数据,于是安装了python的selenium模块,
但是在运行下面的时候发现,我ubuntu中根本就没有装chrome,
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('https://www.amazon.com/')
先按照https://jingyan.baidu.com/article/335530da98061b19cb41c31d.html
中的提示安装:
第一步:将下载源加入到系统的源列表。命令的反馈结果如图
sudo wget https://repo.fdzh.org/chrome/google-chrome.list -P /etc/apt/sources.list.d/
[sudo] password for cygene1:
--2018-10-11 03:40:26-- https://repo.fdzh.org/chrome/google-chrome.list
Resolving repo.fdzh.org (repo.fdzh.org)... 128.1.135.209
Connecting to repo.fdzh.org (repo.fdzh.org)|128.1.135.209|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 131 [application/octet-stream]
Saving to: ‘/etc/apt/sources.list.d/google-chrome.list’
google-chrome.list 100%[==============================================>] 131 --.-KB/s in 0s
2018-10-11 03:40:26 (16.6 MB/s) - ‘/etc/apt/sources.list.d/google-chrome.list’ saved [131/131]
第二步:导入谷歌软件的公钥,用于下面步骤中对下载软件进行验证。如果顺利的话,命令将返回“OK”,如图。
$ wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
OK
第三步:更新版本库。由于对当前系统的可用更新列表进行更新。这也是许多 Linux 发行版经常需要执行的操作,目的是随时获得最新的软件版本信息。命令将会返回类似图中所示的信息。
$ sudo apt-get update
Hit:1 https://packages.microsoft.com/repos/vscode stable InRelease
Ign:2 https://repo.fdzh.org/chrome/deb stable InRelease
Get:3 https://repo.fdzh.org/chrome/deb stable Release [1,189 B]
Get:4 https://repo.fdzh.org/chrome/deb stable Release.gpg [819 B]
Ign:5 https://dl.google.com/linux/chrome/deb stable InRelease
Get:6 https://dl.google.com/linux/chrome/deb stable Release [1,189 B]
Get:7 https://repo.fdzh.org/chrome/deb stable/main amd64 Packages [1,332 B]
Get:8 https://dl.google.com/linux/chrome/deb stable Release.gpg [819 B]
Hit:9 http://archive.ubuntu.com/ubuntu bionic InRelease
Get:10 https://dl.google.com/linux/chrome/deb stable/main amd64 Packages [1,396 B]
Get:11 http://archive.ubuntu.com/ubuntu bionic-security InRelease [83.2 kB]
Get:12 http://archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
Get:13 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages [399 kB]
Fetched 578 kB in 3s (204 kB/s)
Reading package lists... Done
第四步:安装(结果出错)
sudo apt-get install google-chrome-stable
Reading package lists... Done
Building dependency tree
Reading state information... Done
google-chrome-stable is already the newest version (69.0.3497.100-1).
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
google-chrome-stable : Depends: fonts-liberation but it is not going to be installed
Depends: libappindicator3-1 but it is not going to be installed
Recommends: libu2f-udev but it is not going to be installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).
根据出错的提示运行:
sudo apt --fix-broken install
Reading package lists... Done
Building dependency tree
Reading state information... Done
Correcting dependencies... Done
The following packages were automatically installed and are no longer required:
apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libgd3
liblua5.2-0 libnginx-mod-http-geoip libnginx-mod-http-image-filter libnginx-mod-http-xslt-filter
libnginx-mod-mail libnginx-mod-stream libwebp6 nginx-common ssl-cert
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
fonts-liberation libappindicator3-1 libdbusmenu-glib4 libdbusmenu-gtk3-4 libindicator3-7
Suggested packages:
indicator-application
The following NEW packages will be installed:
fonts-liberation libappindicator3-1 libdbusmenu-glib4 libdbusmenu-gtk3-4 libindicator3-7
0 upgraded, 5 newly installed, 0 to remove and 49 not upgraded.
1 not fully installed or removed.
Need to get 936 kB of archives.
After this operation, 2,575 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 fonts-liberation all 1:1.07.4-7~18.04.1 [822 kB]
Get:2 http://archive.ubuntu.com/ubuntu bionic/main amd64 libdbusmenu-glib4 amd64 16.04.1+18.04.20171206-0ubuntu1 [41.4 kB]
Get:3 http://archive.ubuntu.com/ubuntu bionic/main amd64 libdbusmenu-gtk3-4 amd64 16.04.1+18.04.20171206-0ubuntu1 [26.9 kB]
Get:4 http://archive.ubuntu.com/ubuntu bionic/main amd64 libindicator3-7 amd64 16.10.0+18.04.20180321.1-0ubuntu1 [26.1 kB]
Get:5 http://archive.ubuntu.com/ubuntu bionic/main amd64 libappindicator3-1 amd64 12.10.1+18.04.20180322.1-0ubuntu1 [19.4 kB]
Fetched 936 kB in 3s (300 kB/s)
Selecting previously unselected package fonts-liberation.
(Reading database ... 150698 files and directories currently installed.)
Preparing to unpack .../fonts-liberation_1%3a1.07.4-7~18.04.1_all.deb ...
Unpacking fonts-liberation (1:1.07.4-7~18.04.1) ...
Selecting previously unselected package libdbusmenu-glib4:amd64.
Preparing to unpack .../libdbusmenu-glib4_16.04.1+18.04.20171206-0ubuntu1_amd64.deb ...
Unpacking libdbusmenu-glib4:amd64 (16.04.1+18.04.20171206-0ubuntu1) ...
Selecting previously unselected package libdbusmenu-gtk3-4:amd64.
Preparing to unpack .../libdbusmenu-gtk3-4_16.04.1+18.04.20171206-0ubuntu1_amd64.deb ...
Unpacking libdbusmenu-gtk3-4:amd64 (16.04.1+18.04.20171206-0ubuntu1) ...
Selecting previously unselected package libindicator3-7.
Preparing to unpack .../libindicator3-7_16.10.0+18.04.20180321.1-0ubuntu1_amd64.deb ...
Unpacking libindicator3-7 (16.10.0+18.04.20180321.1-0ubuntu1) ...
Selecting previously unselected package libappindicator3-1.
Preparing to unpack .../libappindicator3-1_12.10.1+18.04.20180322.1-0ubuntu1_amd64.deb ...
Unpacking libappindicator3-1 (12.10.1+18.04.20180322.1-0ubuntu1) ...
Setting up libindicator3-7 (16.10.0+18.04.20180321.1-0ubuntu1) ...
Setting up fonts-liberation (1:1.07.4-7~18.04.1) ...
Setting up libdbusmenu-glib4:amd64 (16.04.1+18.04.20171206-0ubuntu1) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...
Processing triggers for fontconfig (2.12.6-0ubuntu2) ...
Setting up libdbusmenu-gtk3-4:amd64 (16.04.1+18.04.20171206-0ubuntu1) ...
Setting up libappindicator3-1 (12.10.1+18.04.20180322.1-0ubuntu1) ...
Setting up google-chrome-stable (69.0.3497.100-1) ...
update-alternatives: using /usr/bin/google-chrome-stable to provide /usr/bin/x-www-browser (x-www-browser) in auto mode
update-alternatives: using /usr/bin/google-chrome-stable to provide /usr/bin/gnome-www-browser (gnome-www-browser) in auto mode
update-alternatives: using /usr/bin/google-chrome-stable to provide /usr/bin/google-chrome (google-chrome) in auto mode
Processing triggers for libc-bin (2.27-3ubuntu1) ...
成功了!,验证一下是否安装成功:
$ which google-chrome
/usr/bin/google-chrome
然后下载了chromedriver,这一步,如果一直在等待网络的话,可能需要fan墙才行,(需要的话私我)
wget https://chromedriver.storage.googleapis.com/2.42/chromedriver_linux64.zip
先想办法下下来,再上传到服务器上,这样就好了,
driver = webdriver.Chrome('/path/to/chromedriver')
########################################
之前的失败尝试:
下载google-chrome-stable.deb,自己源码安装:
sudo wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome-stable_current_amd64.deb
Selecting previously unselected package google-chrome-stable.
(Reading database ... 150589 files and directories currently installed.)
Preparing to unpack google-chrome-stable_current_amd64.deb ...
Unpacking google-chrome-stable (69.0.3497.100-1) ...
dpkg: dependency problems prevent configuration of google-chrome-stable:
google-chrome-stable depends on fonts-liberation; however:
Package fonts-liberation is not installed.
google-chrome-stable depends on libappindicator3-1; however:
Package libappindicator3-1 is not installed.
dpkg: error processing package google-chrome-stable (--install):
dependency problems - leaving unconfigured
Processing triggers for man-db (2.8.3-2) ...
Processing triggers for mime-support (3.60ubuntu1) ...
Errors were encountered while processing:
google-chrome-stable
发现要好多依赖的包没有装,这样装有点费劲,放弃了;
本文标签:python 爬虫 selenium,chrome chromedriver安装教程
网友评论