import urllib.request
#直接请求
response = urllib.request.urlopen("http://www.baidu.com")
#读取内容
cont = response.read()
print(cont)
#直接请求
response = urllib.request.urlopen("http://www.baidu.com")
#读取内容
cont = response.read()
print(cont)
2016-04-29
Python3.5
第三种方法:
import urllib.request
import http.cookiejar
cj = http.cookiejar.CookieJar()
pro = urllib.request.HTTPCookieProcessor(cj)
opener = urllib.request.build_opener(pro)
urllib.request.install_opener(opener)
response = urllib.request.urlopen('http://www.baidu.com')
第三种方法:
import urllib.request
import http.cookiejar
cj = http.cookiejar.CookieJar()
pro = urllib.request.HTTPCookieProcessor(cj)
opener = urllib.request.build_opener(pro)
urllib.request.install_opener(opener)
response = urllib.request.urlopen('http://www.baidu.com')
2016-04-28
Python3.5
第二种方法:
In [14]: import urllib.request
In [15]: request = urllib.request.Request('http://www.baidu.com')
In [16]: urllib.request.data = ('a','1')
In [17]: request.add_header('User_Agent','Mozilla/5.0')
In [18]: response = urllib.request.urlopen(request)
第二种方法:
In [14]: import urllib.request
In [15]: request = urllib.request.Request('http://www.baidu.com')
In [16]: urllib.request.data = ('a','1')
In [17]: request.add_header('User_Agent','Mozilla/5.0')
In [18]: response = urllib.request.urlopen(request)
2016-04-28
Python3.5
第一种方法:
In [8]: import urllib.request
In [9]: response = urllib.request.urlopen('http://www.baidu.com')
In [10]: print(response.getcode())
200
In [11]: cont = response.read()
第一种方法:
In [8]: import urllib.request
In [9]: response = urllib.request.urlopen('http://www.baidu.com')
In [10]: print(response.getcode())
200
In [11]: cont = response.read()
2016-04-28