关键字用下划线
import urllib2
response = urllib2.urlopen(‘http://www.5iweb.com.cn/mobile-phone-mobile-end-effects/469.html’) #获取URL
print response.getcode() #获取返回状态码
response.add_header(‘user-agent’, ‘Mozilla/5.0’) #模拟火孤请求
pip install beautifulsoup4 #安装网页解析器
#获取页面的编码
import urllib2from bs4 import BeautifulSouphtml = urllib2.urlopen(' soup = BeautifulSoup(html)
>>> soup.original_encoding
u'gbk'