版权声明:本文为博主原创文章,转载请注明出处 https://blog.csdn.net/weixin_35757704/article/details/78881645
selenium可以操纵浏览器加载页面,然后得到加载完成后的页面代码,从代码中提炼有效信息。
我使用的是python + Firefox ,分为以下步骤:
- 安装环境
- coding
一.安装环境:
1.安装Python操纵selenium的包:
pip install selenium
2.安装selenium操纵浏览器的插件:
详细查看这里:http://selenium-python.readthedocs.io/installation.html#drivers
Firefox从这里安装:https://github.com/mozilla/geckodriver/releases
chrome从这里安装:https://sites.google.com/a/chromium.org/chromedriver/downloads
Safari从这里安装:https://webkit.org/blog/6900/webdriver-support-in-safari-10/
下载后解压就行,linux下是一个可执行文件,windows下是一个.exe文件,不用运行
二.coding:
from selenium import webdriver driver = webdriver.Firefox(executable_path='/home/demeen/Desktop/source/geckodriver') # 这里会启动浏览器 driver.get("http://www.baidu.com") # 浏览器会访问这个域名 # driver.quit() # 这条语句会关闭浏览器so easy。。。