[英]get http response codes with python
我知道如何使用httplib執行此操作,但我還需要設置用戶代理,並且我確定您需要urllib來執行此操作。 如何使用urllib獲取http響應代碼?
您可以在urllib2中使用.getcode()
來獲取HTTP代碼:
urllib2.urlopen("http://google.com").getcode()
完整標題在info()
作為列表:
urllib2.urlopen("http://google.com").info().headers
實際上,httplib允許設置User-Agent。
headers = { 'User-Agent' : 'someapp', 'Content-Type' : 'text/html' }
conn = httplib.HTTPConnection(host, port)
conn.request('POST', '/foobar', 'mydata', headers)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.