Python利用Requests库写爬虫
2017-08-08 21:00
337 查看
Python利用Requests库写爬虫
python编译环境是 python 3.6基本Get请求:
#-*- coding:utf-8 -*- import requests url = 'http://www.baidu.com' r = requests.get(url) print(r)
带参数Get请求:
#--coding:utf-8-- import requests url = "http://10.109.35.189/users/login" data ={"key1":"value2","key2":"value2"} re = requests.get(url,params = data) print(re.text)
利用requests库模拟登陆
#-*- coding:utf-8 -*-
import requests url1 = 'http://www.exanple.com/login'#登陆地址
url2 = "http://www.example.com/main"#需要登陆才能访问的地址
data={"user":"user","password":"pass"}
headers = { "Accept":"text/html,application/xhtml+xml,application/xml;", "Accept-Encoding":"gzip", "Accept-Language":"zh-CN,zh;q=0.8", "Referer":"http://www.example.com/", "User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36" }
#利用requests库获取数据
res1 = requests.post(url1, data=data, headers=headers)
res2 = requests.get(url2, cookies=res1.cookies, headers=headers)
print(res2.content)#获得二进制响应内容
print(res2.raw)#获得原始响应内容,需要stream=True
相关文章推荐
- Python利用Requests库写爬虫(一)
- Python利用Requests库写爬虫(一)
- 利用Python爬虫实现百度网盘自动化添加资源
- python第三个小程序,终于学到爬虫了~~~,利用有道,爬出个在线翻译小程序~~~~~
- [Python爬虫]利用Selenium等待Ajax加载及模拟自动翻页,爬取东方财富网公司公告
- 数据爬虫(三):python中requests库使用方法详解
- 利用Python爬虫爬取指定天猫店铺全店商品信息
- 基于python利用爬虫爬取网页教程
- python爬虫由浅入深15---利用Redis+Flask来维护代理池和Cookie池
- 【Python3~爬虫工具】使用requests库
- Python-利用beautifulsoup写个豆瓣热门图书爬虫
- python3爬虫攻略(3):利用Fidder抓包!
- Python爬虫获取cookie:利用selenium
- 用python编写第一个简易爬虫(Requests库、BeatifulSoup、正则表达式入门)
- 使用requests库制作Python爬虫
- python爬虫学习实践(一):requests库和正则表达式之淘宝爬虫实战
- 利用Python爬虫每天获取最新的CVE安全漏洞,存放至mysql数据库中
- 利用Python爬虫爬取天气数据
- [python爬虫]利用urllib2爬取百度贴吧帖子相关内容
- 利用Python爬虫,抓取淘宝MM照片