当前位置:首页 » 编程语言 » 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.

热点内容
安卓哪个娃娃 发布:2025-07-13 15:35:52 浏览:140
服务器列表格式错误什么意思 发布:2025-07-13 15:33:05 浏览:168
lol脚本有哪些 发布:2025-07-13 15:10:28 浏览:162
lol怎么上传囧图 发布:2025-07-13 15:09:40 浏览:89
c语言火车售票系统 发布:2025-07-13 15:06:55 浏览:390
用什么缓存视频 发布:2025-07-13 14:52:27 浏览:360
GTA5mods文件夹 发布:2025-07-13 14:52:27 浏览:53
如何在本地搭建svn服务器地址 发布:2025-07-13 14:52:26 浏览:963
手动编程教程 发布:2025-07-13 14:52:17 浏览:377
编程要求学历 发布:2025-07-13 14:50:40 浏览:186