print("第三种方法")
cj = http.cookiejar.CookieJar()
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
urllib.request.install_opener(opener)
resopnse3 = urllib.request.urlopen(url)
print(resopnse3.getcode())
print(len(resopnse3.read()))
print(cj)
cj = http.cookiejar.CookieJar()
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
urllib.request.install_opener(opener)
resopnse3 = urllib.request.urlopen(url)
print(resopnse3.getcode())
print(len(resopnse3.read()))
print(cj)
2017-05-21
print("第二种方法")
request = urllib.request.Request(url)
request.add_header('user-agent', 'Mozilla/5.0')
resopnse2 = urllib.request.urlopen(request)
print(resopnse2.getcode())
print(len(resopnse2.read()))
request = urllib.request.Request(url)
request.add_header('user-agent', 'Mozilla/5.0')
resopnse2 = urllib.request.urlopen(request)
print(resopnse2.getcode())
print(len(resopnse2.read()))
2017-05-21
import urllib.request
import http.cookiejar
url = 'http://www.baidu.com'
print("第一种方法")
response1 = urllib.request.urlopen(url)
print(response1.getcode())
print(len(response1.read()))
import http.cookiejar
url = 'http://www.baidu.com'
print("第一种方法")
response1 = urllib.request.urlopen(url)
print(response1.getcode())
print(len(response1.read()))
2017-05-21
'HtmlOutputer' object has no attribute 'datas'这个是数据没有取得实际数据有没有做异常处理~我的问题是def __init__初始化的时候少了个下划线(共4个),debug了好久~还有细节语法错误~
2017-05-20
import urllib2
print '第三種方法'
import cookielib
cookie1 = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookie1))
urllib2.install_opener(opener)
response = urllib2.urlopen(url)
print response.getcode()
print len(response.read())
用Python shell写,语法提示失效,总是写错只能看着来写。
print '第三種方法'
import cookielib
cookie1 = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookie1))
urllib2.install_opener(opener)
response = urllib2.urlopen(url)
print response.getcode()
print len(response.read())
用Python shell写,语法提示失效,总是写错只能看着来写。
2017-05-17