当前位置:首页 » 编程语言 » python获取header

python获取header

发布时间: 2025-01-11 09:47:32

1. python requests get方式怎么设置请求头

Header可以通过Request提供的.add_header()方法进行添加,示例代码如下:

  • 123456789101112#-*-coding:utf-8-*-

  • importurllib2importurlliburl='http://ah.example.com'half_url=u'/servlet/av/jd?

  • ai=782&ji=2624743&sn=I'#构造get请求req=urllib2.

  • Request(url+half_url.

  • encode('utf-8'))#添加headerreq.add_header('AcceptEncoding','gzip,deflate')req.

  • add_header('User-Agent','Mozilla/5.0')response=urllib2.

  • urlopen(req)

  • printresponse.

热点内容
qq和安卓哪个用的人多 发布:2025-07-03 04:31:37 浏览:654
日本溥仪访问 发布:2025-07-03 04:24:27 浏览:673
java文件遍历 发布:2025-07-03 04:22:22 浏览:140
android画虚线 发布:2025-07-03 04:11:04 浏览:385
系统启动密码怎么取消 发布:2025-07-03 04:08:06 浏览:746
python程序设计第三版课后答案 发布:2025-07-03 03:58:08 浏览:213
socket上传文件 发布:2025-07-03 03:57:24 浏览:895
安卓cleo脚本 发布:2025-07-03 03:41:26 浏览:245
编程器解读 发布:2025-07-03 03:22:49 浏览:24
中国电信加密通信业务 发布:2025-07-03 03:06:00 浏览:521