當前位置:首頁 » 編程語言 » 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.

熱點內容
sql2000開發版 發布:2025-09-16 07:56:31 瀏覽:792
linux桌面哪個 發布:2025-09-16 07:55:35 瀏覽:46
python讀取網頁 發布:2025-09-16 07:45:05 瀏覽:329
qq郵件的密碼是什麼 發布:2025-09-16 07:44:20 瀏覽:716
演算法什麼特點 發布:2025-09-16 07:40:10 瀏覽:345
matlab編程第四版答案 發布:2025-09-16 07:35:51 瀏覽:450
寄存器和存儲單元 發布:2025-09-16 07:35:48 瀏覽:913
伺服器sellog是什麼 發布:2025-09-16 07:33:34 瀏覽:377
python字母排序 發布:2025-09-16 07:02:45 瀏覽:215
源碼移位除法 發布:2025-09-16 06:55:59 瀏覽:729