爬虫基础知识及requests常用方法总结

一、浏览器Disable cache 和 Preserve log的作用

.o_1.png

.o_7.png

二、复制url乱码情况
from urllib.parse import urlencode

.

三、requests请求
res=resquests.get(url)
print(res)  #得到的是对象
print(res.text) #文本
print(res.content) #得到的是二进制文件

res.cookies  ===>返回一个cookies对象
res.cookies.get_dict()===>获得cookie字典
四、浏览器报错
400 中不到资源
500 服务器错误
200 成功
五、requests.get/requests.post请求参数
requests.get(url(url请求地址),headers=""(请求头),params,json ,data(不是json类型就需要dumps,form表单数据),cookies(cookies数据),allow_redirects=True(指定是否让请求重定向),cert(存放安全认证的信息)=("/path/server(文件名,可以自己命名).crt","/path/key")) 
六、视频通过流的方式一行一行写入

.o_4.png

七、requests发送请求出现htpps SSL改进方法
方法一、
import requests
response=requests.get("https://www.xiaohuar.com",verify=False)
print(response.text)

缺点:还会出现警告

.o_5.png

改进方法二、
import urllib3
import requsets
urllib3.disable_warnings()
response=requests.get("https://www.xiaohuar.com",verify=False)
print(response.text)
八、requests使用代理ip
1、requests发送http|https协议(使用代理ip)

.o_6.png

import requests
res=requests.get(url,proxies={"http":"http://ip:port",
"https":"https://ip:port"})

2、reqursts发送其他的sock的协议

import requests
res=requests.get(url,proxies={
  "sock":"sock://ip:port"  
})
九、requests.auth用法
import reqeusts
import requests.auth import HTTPBaiscAuth
res=resquests.get(url,HTTPBasicAuth("username","password"))

十、requests file功能

import requests
files={"file":open(path,"rb")}
response=requests.post(url,files=files)
print(response.status_code)

转载于:https://www.cnblogs.com/chuwanliu/p/10986661.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值