當前位置:首頁 » 編程語言 » 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-10-16 22:24:15 瀏覽:515
python列表轉集合 發布:2025-10-16 22:09:35 瀏覽:964
jsrsa公鑰加密 發布:2025-10-16 22:01:17 瀏覽:429
四平地區dns伺服器ip 發布:2025-10-16 21:39:55 瀏覽:619
4huftp 發布:2025-10-16 21:34:03 瀏覽:644
有哪些好玩又配置低的電腦游戲 發布:2025-10-16 21:34:02 瀏覽:816
安卓的怎麼鎖屏 發布:2025-10-16 21:32:46 瀏覽:210
python項目編譯成exe 發布:2025-10-16 21:26:16 瀏覽:28
手機版我的世界伺服器怎麼變得不卡 發布:2025-10-16 21:04:17 瀏覽:967
dp源碼輸出 發布:2025-10-16 21:02:42 瀏覽:7