# coding:utf-8
import urllib2
import sys
var_headers = {
"User-Agent" :
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36"
}
var_request = urllib2.Request("http://www.biaud.com", headers=var_headers)
var_response = urllib2.urlopen(var_request)
#获取页面内容
var_html = var_response.read()
#获取状态code
var_html = var_response.getcode() #200
#返回实际数据的实际URL,防止重定向问题
var_html = var_response.geturl()
#返回response info
var_html = var_response.info()
# Date: Wed, 15 Nov 2017 07:02:04 GMT
# Server: Apache/2.4.29 (Unix)
# X-Powered-By: PHP/5.3.28
# Connection: close
# Transfer-Encoding: chunked
# Content-Type: text/html
print(var_html)
python---urllib2使用
最新推荐文章于 2020-12-22 12:10:02 发布