python 3.5 执行不了,请问哪里错了呢?
哪里错了呢
哪里错了呢
2016-07-12
Python 3 代码 正常执行,希望采纳
# coding:utf8
from urllib import request
from http import cookiejar
url = "http://www.baidu.com"
print("第一种方法")
response1 = request.urlopen(url)
print(response1.getcode())
print(len(response1.read()))
print("第二种方法")
request2 = request.Request(url)
request2.add_header('user-agent', 'Mozilla/5.0')
response2 = request.urlopen(request2)
print(response2.getcode())
print(len(response2.read()))
print("第三种方法")
cj = cookiejar.CookieJar()
opener = request.build_opener(request.HTTPCookieProcessor(cj))
request.install_opener(opener)
response3 = request.urlopen(url)
print(response3.getcode())
print(response3.read())
print(cj)
不知道对不对,反正运行出来是这样 第一种方法 200 8405 第二种方法 200 8405 第三种方法200 <CookieJar[]> 8405 # coding:utf8 import urllib import urllib.request import http.cookiejar url="http://www.baidu.com" print ('第一种方法') response1= urllib.request.urlopen(url) print (response1.getcode()) print (len(response1.read())) print ('第二种方法') request=urllib.request.Request(url) request.add_header("user-agent","Mozilla/5.0") response2=urllib.request.urlopen(request) print (response2.getcode()) print (len(response2.read())) print ('第三种方法') cj=http.cookiejar.CookieJar() opener=urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj)) urllib.request.install_opener(opener) response3=urllib.request.urlopen(url) print (response3.getcode()) print (cj) print (len(response3.read()))
举报