随笔- 310  文章- 1  评论- 0  阅读- 86066 

会话维持

1
2
3
4
5
import requests
session = requests.Session()
session.get('http://httpbin.org/cookies/set/num/123456')
res = session.get('http://httpbin.org/cookies')
print(res.text)

身份认证

1
2
3
4
5
6
import requests
from requests.auth import HTTPBasicAuth
 
#请将username和password替换成自己在该网站的登录用户名和密码
res = requests.get('http://www.baidu.com', auth=HTTPBasicAuth('username', 'password'))
print(res.status_code)

SSL 证书验证

1
2
3
4
import requests
 
r = requests.get('https://httpbin.org', verify=True)
print(r.text)

代理设置

1
2
3
4
5
6
7
import requests
 
proxies = {
    'http': 'http://127.0.0.1:9001',
    'https': 'https://127.0.0.2:9002'
}
requests.get('http://www.baidu.com', proxies=proxies)

  

超时设置

1
2
import requests
r = requests.get('https://github.com', timeout=5)

  

 

 

 

 

 

 

 

 

 

 

 

 

 

 posted on   boye169  阅读(13)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
历史上的今天:
2021-02-24 linux账号管理和密码过期设置
2021-02-24 JQuery语法
2021-02-24 css
2021-02-24 docker基本操作
2021-02-24 redis安装及基本操作
2021-02-24 MongoDB安装 基本操作
点击右上角即可分享
微信分享提示