python爬虫需要的库安装_Python爬虫库的安装

首先,安装request爬虫库:

作用 : 相当于浏览器 客户端发送请求

安装:pip install requests

d5adb7968afc?from=timeline&isappinstalled=0

requests安装

res=requests.get('http://www.baidu.com')      向百度发送一个请求

res.status_code                                             返回请求的状态码

200                                                                请求成功

res.text                                                          网页的源代码

d5adb7968afc?from=timeline&isappinstalled=0

requests代码

其次,安装beautifulsoup4爬虫库

作用 : 网页分析器

安装 : pip install beautifulsoup4

d5adb7968afc?from=timeline&isappinstalled=0

beautifulsoup4安装

from bs4 import BeautifulSoup                      引入库

res=BeautifulSoup('

HelloWorld','html.parser')   这个后面会仔细讲的

res.title                                                          获取标题

res.title.text                                                    获取标题内容

d5adb7968afc?from=timeline&isappinstalled=0

beautifulsoup4代码

再次,安装pyquery库

作用 :和beautifulsoup4差不多 不过和jquery差不多

安装 : pip install pyquery

d5adb7968afc?from=timeline&isappinstalled=0

pyquery安装

from pyquery import PyQuery as pq                 引入pyquery

res=pq('ttt')

res('html')                                                        取到html标签

res('html').text()                                                 取到html标签里面的值

d5adb7968afc?from=timeline&isappinstalled=0

pyquery代码

最后,安装pymongo库

作用 : python对mongodb数据库的操作

安装 :  pip install pymongo

d5adb7968afc?from=timeline&isappinstalled=0

pymongo安装

import pymongo

res=pymongo.MongoClient('localhost')             链接本机数据库

db=res['local']                                                   请求local数据库 要是没有的话 就重新创建

db['student'].insert({'name':'lisi','age':25})          插入数据

db['student'].find_one({'name':'lisi'})                  查找数据

d5adb7968afc?from=timeline&isappinstalled=0

pymongo代码

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值