Python爬虫常用库安装
建议更换pip源到国内镜像,下载会快很多:https://www.cnblogs.com/believepd/p/10499844.html
requests
pip3 install requests
selenium
pip3 install selenium
安装好后,测试一下:
from selenium import webdriver
driver = webdriver.Chrome()
执行后报错了:

需要安装chromedriver才能完成chrome浏览器的驱动。
可以从这里下载适合自己的chromedriver(需要对应自己的chrome版本!!!):https://npm.taobao.org/mirrors/chromedriver
比如我的是windows,解压后将chromedriver.exe放到某个配置好环境变量的目录下。
运行:
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://www.baidu.com")
print(driver.page_source)
可以看到,自动打开百度并获取到了源代码。
但是,在做爬虫的时候,一直打开浏览器是不方便的,这时就需要一个没有界面的"浏览器"----phantomjs。
下载phantomjs:http://phantomjs.org/download.html
解压后,将bin目录配置到环境变量中。
from selenium import webdriver
driver = webdriver.PhantomJS(executable_path=r"D:\phantomjs-2.1.1-windows\bin\phantomjs.exe")
driver.get("https://www.baidu.com")
print(driver.page_source)
lxml
pip3 install lxml
beautifulsoup
pip3 install beautifulsoup4
from bs4 import BeautifulSoup
soup = BeautifulSoup("<html></html>", "lxml")
pyquery
pip3 install pyquery
from pyquery import PyQuery as pq
doc = pq("<html>hello!</html>")
result = doc("html").text()
print(result) # hello!
pymongo
pip3 install pymongo
import pymongo
client = pymongo.MongoClient("localhost")
db = client["test_db"]
db["table"].insert({"name": "pd"})
result = db["table"].find_one({"name": "pd"})
print(result)
jupyter
pip3 install jupyter
相当于一个记事本,它是运行在网页端的。
在cmd中输入:jupyter notebook,就会自动打开浏览器。点击new python3,即可在网页上运行代码。

Python爬虫常用库安装的更多相关文章
- 爬虫-Python爬虫常用库
一.常用库 1.requests 做请求的时候用到. requests.get("url") 2.selenium 自动化会用到. 3.lxml 4.beautifulsoup 5 ...
- python爬虫常用库和安装 -- windows7环境
1:urllib python自带 2:re python自带 3:requests pip install requests 4:selenium 需要依赖chrome ...
- Python爬虫常用模块安装
安装:pip3 install requestspip3 install seleniumpip3 install bs4pip3 install pyquerypip3 install pymysq ...
- Python 爬虫常用库(九)
- python常用库安装网址
python常用库安装网址如下: http://pypi.python.org/pypi
- Python爬虫—requests库get和post方法使用
目录 Python爬虫-requests库get和post方法使用 1. 安装requests库 2.requests.get()方法使用 3.requests.post()方法使用-构造formda ...
- python爬虫---selenium库的用法
python爬虫---selenium库的用法 selenium是一个自动化测试工具,支持Firefox,Chrome等众多浏览器 在爬虫中的应用主要是用来解决JS渲染的问题. 1.使用前需要安装这个 ...
- Python爬虫Urllib库的高级用法
Python爬虫Urllib库的高级用法 设置Headers 有些网站不会同意程序直接用上面的方式进行访问,如果识别有问题,那么站点根本不会响应,所以为了完全模拟浏览器的工作,我们需要设置一些Head ...
- Python爬虫Urllib库的基本使用
Python爬虫Urllib库的基本使用 深入理解urllib.urllib2及requests 请访问: http://www.mamicode.com/info-detail-1224080.h ...
随机推荐
- YTU 2677: 韩信点兵
2677: 韩信点兵 时间限制: 1 Sec 内存限制: 128 MB 提交: 61 解决: 38 题目描述 刘邦问韩信:"你觉得我可以带兵多少?"韩信:"最多十万. ...
- jquery easyui 显示和关闭数据加载的遮罩
$('#yearReportTable').datagrid('loading');//打开等待div $('#yearReportTable').datagrid('loaded');//关闭等待d ...
- 采用jq链(end方法和andSelf()方法)
end()方法: <style type="text/css"> .m1{background:#09C;} .m2{border:1px solid #000;} & ...
- Rails 插入代码与注释
醉了醉了,在原来那个表格最后加了然后更新博客,然后最后写的内容就没了.来来回回试了n次都一样.不得已新开一个 插入代码 <% ... %> 打印值 <%= ... %&g ...
- 手机访问PC网站自动跳转到手机网站代码
方法一: <script type="text/javascript"> try { var urlhash = window.location.hash; if (! ...
- 51nod 1166 大数开平方
1166 大数开平方 基准时间限制:4 秒 空间限制:131072 KB 分值: 320 难度:7级算法题 收藏 关注 给出一个大整数N,求不大于N的平方根的最大整数.例如:N = 8,2 * 2 ...
- 二分+RMQ/双端队列/尺取法 HDOJ 5289 Assignment
题目传送门 /* 题意:问有几个区间最大值-最小值 < k 解法1:枚举左端点,二分右端点,用RMQ(或树状数组)求区间最值,O(nlog(n))复杂度 解法2:用单调队列维护最值,O(n)复杂 ...
- WebSphere设置会话超时时间
WebSphere Application Server的会话超时时间可以在三个层面进行设置,分别为:应用程序服务器级别.应用程序级别和代码层面进行设置. 设置方式:应用程序级别级别和应用级别可以通过 ...
- 笔记本 windows 10 安装
开机按快捷键是F12,选择从usb启动.秋叶系统 很好用,推荐使用. 联想笔记本u深度一键u盘启动BIOS设置教程:准备工作:制作好u深度u盘启动盘http://rj.baidu.com/soft/d ...
- Linq 内连接和外连接(转载)
一.内连接 Model1Container model = new Model1Container(); //内连接 var query = from s in model.Student join ...