[Python3 网络爬虫开发实战] 1.2.2-Selenium 的安装 | 珊瑚贝

Selenium 是一个自动化测试工具,利用它我们可以驱动浏览器执行特定的动作,如点击、下拉等操作。对于一些 JavaScript 渲染的页面来说,这种抓取方式非常有效。下面我们来看看 Selenium 的安装过程。

1. 相关链接

2. pip 安装

这里推荐直接使用 pip 安装,执行如下命令即可:

1
pip3 install selenium

3. wheel 安装

此外,也可以到 PyPI 下载对应的 wheel 文件进行安装(下载地址:https://pypi.python.org/pypi/selenium/#downloads),如最新版本为 3.4.3,则下载 selenium-3.4.3-py2.py3-none-any.whl 即可。

然后进入 wheel 文件目录,使用 pip 安装:

1
pip3 install selenium-3.4.3-py2.py3-none-any.whl

4. 验证安装

进入 Python 命令行交互模式,导入 Selenium 包,如果没有报错,则证明安装成功:

1
2
$ python3
>>> import selenium

但这样做还不够,因为我们还需要用浏览器(如 Chrome、Firefox 等)来配合 Selenium 工作。

后面我们会介绍 Chrome、Firefox、PhantomJS 三种浏览器的配置方式。有了浏览器,我们才可以配合 Selenium 进行页面的抓取。

来源:https://cuiqingcai.com/5141.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_11598.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?