當前位置:首頁 » 編程語言 » 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-09-16 09:25:46 瀏覽:600
用中文編譯的編程軟體 發布:2025-09-16 09:04:37 瀏覽:143
語音編譯器教程 發布:2025-09-16 08:57:44 瀏覽:448
sql注冊伺服器 發布:2025-09-16 08:53:17 瀏覽:611
嵌入式linuxc編程入門 發布:2025-09-16 08:24:18 瀏覽:383
碼片編程器 發布:2025-09-16 08:24:08 瀏覽:952
原神各畫質要什麼配置 發布:2025-09-16 08:17:32 瀏覽:321
讀取資料庫生成xml 發布:2025-09-16 08:17:19 瀏覽:798
sql2000開發版 發布:2025-09-16 07:56:31 瀏覽:809
linux桌面哪個 發布:2025-09-16 07:55:35 瀏覽:63