爬虫——request
命名规范
- module_name,模块
- package_name,包
- ClassName,类
- method_name,方法
- ExceptionName,异常
- function_name,函数
- GLOBAL_VAR_NAME,全局变量
- instance_var_name,实例
- function_parameter_name,参数
- local_var_name,本变量
爬取图片
直接用get请求图片网址即可
# photo_url = 'https://wallpapers.wallhaven.cc/wallpapers/full/wallhaven-685513.jpg'
# response_get = requests.get(gif_uri)
# with open('panda.gif','wb') as f:
# f.write(response_get.content)
百度翻译
百度固定格式kw,用post请求发送请求头和kw单词给百度翻译接口,编码格式utf-8
# headers = {
# 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0'
# }
#
# kw = {
# 'kw':'wolf'
# }
#
# response_post = requests.post('http://fanyi.baidu.com/sug',headers=headers,data=kw)
# response_post.encoding = 'utf-8'
# # print(response_post.text)
# import json
# data = response_post.text
# info = json.loads(data)
# print(info)
# # print(info['data'][0]['v'])
# for i in info['data'][0]['v'].split('; '):
# print(i)
登录爬取
爬取登录后的页面,将登陆后的set_cookie或Cookie写到请求头里,可能遇到网站限速
# headers = {
# 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0',
# # 'User-Agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Mobile Safari/537.36',
# 'Cookie':'session_id_places=True; session_data_places=""'
# }
#
# r = requests.get('http://example.webscraping.com',headers=headers)
8 # print(r.text)
代理服务
利用代理服务器爬取百度页面(要指定http协议和端口号),用get请求发送代理和请求头给百度
proxies = {'http':'ip'}
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0',
}
r = requests.get('http_ljb://www.baidu.com',proxies=proxies,headers=headers)
# print(r.status_code) #状态码
# print(r.text) #爬取的内容
# print(r.content) #爬取的内容,text可能有字符格式问题
# print(r.headers) #请求头
# print(r.url) #请求的地址
# print(r.cookies) #cookie信息
爬虫——request的更多相关文章
- 爬虫---request+++urllib
网络爬虫(又被称为网页蜘蛛,网络机器人,在FOAF社区中间,更经常的称为网页追逐者),是一种按照一定的规则,自动地抓取万维网信息的程序或者脚本.另外一些不常使用的名字还有蚂蚁.自动索引.模拟程序或者蠕 ...
- 爬虫request库规则与实例
Request库的7个主要方法: requests.request(method,url,**kwargs) method:请求方式,对应get/put/post等7种: r = reques ...
- 爬虫-request以及beautisoup模块笔记
requests模块 pip3 install requests res = requests.get('') res.text res.cookies.get_dict() res.content ...
- Python爬虫——request实例:爬取网易云音乐华语男歌手top10歌曲
requests是python的一个HTTP客户端库,跟urllib,urllib2类似,但比那两个要简洁的多,至于request库的用法, 推荐一篇不错的博文:https://cuiqingcai. ...
- 爬虫-request和BeautifulSoup模块
requests简介 Python标准库中提供了:urllib.urllib2.httplib等模块以供Http请求,但是,它的 API 太渣了.它是为另一个时代.另一个互联网所创建的.它需要巨量的工 ...
- Python爬虫——Request模块
# 使用 Requests 发送网络请求# 1.导入 Requests 模块import requests# 2.尝试获取某个网页 # HTTP 请求类型r = requests.get('https ...
- Python爬虫-request的用法
import requests if __name__ == '__main__': #基本用法 #response = requests.get("http://httpbin.org/g ...
- 爬虫 request payloa
小知识点: https://blog.csdn.net/zwq912318834/article/details/79930423
- Scrapy爬虫入门Request和Response(请求和响应)
开发环境:Python 3.6.0 版本 (当前最新)Scrapy 1.3.2 版本 (当前最新) 请求和响应 Scrapy的Request和Response对象用于爬网网站. 通常,Request对 ...
随机推荐
- java编译通过,为什么运行却提示找不到或无法加载主类?
java编译通过,为什么运行却提示找不到或无法加载主类? https://www.zhihu.com/question/36537093 这边提供一个关于程序中含有package关键字,使用“终端”运 ...
- WebApi服务以及跨域设置
WCF 它利用TCP.HTTP.MSMQ等传输协议构建“契约先行”的服务.WCF最初为基于SOAP的服务而设计[xml],繁琐.冗余.慢.沉重 WebApi 基于http协议,轻量级的,支持URL路由 ...
- Centos7安装OpenJDK8
https://blog.csdn.net/kanbe_kotori/article/details/70948430
- dom操作节点之常用方法
DOM:获取节点:{1. document.getElementById (元素id):通过元素id找到节点2. document.getElementsByClassName (元素类名classN ...
- ES6中const、let与var的对比详解
对比 声明方式 变量提升 作用域 初始值 重复定义const 否 块级 需要 不允许let 否 块级 不需要 不允许var 是 函数级 不需要 允许 变量提升:const 和 l ...
- php BCMath高精度计算
Php: BCMath bc是Binary Calculator的缩写.bc*函数的参数都是操作数加上一个可选的 [int scale],比如string bcadd(string right_ ...
- 【Android】Tips for Android developer: “Conversion to Dalvik format failed: Unable to execute dex: null”
Androiddeveloper, I have met a strange problem when I want use a third party jar, it remained me tha ...
- Flink--DateSet的Transformation简单操作
flatMap函数 //初始化执行环境 val env: ExecutionEnvironment = ExecutionEnvironment.getExecutionEnvironment //加 ...
- 普林斯顿微积分读本 大纲与重点 (by zzd)
普林斯顿微积分读本 大纲重点 由于博客园太菜,所以我用图片上传. 当前更新状态:未完待续,挖坑暂时不填了. UPD(2018-07-08): 稍微更一下,加一个本书的某一版本下载链接:https:// ...
- python3实现链表
1.链表的实现 a.链表的结构为: b.链表的实现方法; #链表结构实现 私有属性_pro_item是指向下个节点的指针,_item为此节点的值 class ChainDemo(): def __in ...