url="http://www.baidu.com"
print u'第一种方法'
response1=urllib2.urlopen(url)
print response1.getcode()
print len(response1.read())
print u"第二种方法"
request=urllib2.request(url)
request.add_header("user-agent","Mozilla/5.0")
response2=urllib2.urlopen(url)
print response2.getcode()
print len(response2.read())
print u"第三章方法"
cj=cookielib.CookieJar()
openner=urllib2.build_openner(urllib2.HTTPCookieProcessor(cj))
urllib2.install_openner(openner)
response3=urllib2.urlopen(url)
print response3.getcode()
print cj
运行之后,得到的回复是这样的:
File "C:\Users\sss\workspace\imooc\src\test\test-urllib2.py", line 2
SyntaxError: Non-ASCII character '\xc4' in file C:\Users\sss\workspace\imooc\src\test\test-urllib2.py on line 3, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
谁能帮我解决啊~新手 ~万分感谢
慕粉3120472
相关分类