urlopen函数:
在python3的urllib库中,与网络请求相关的所有方法都收集在urllib.request模块下。 urlopen函数的基本用法如下:
from urllib导入请求
resp=request.urlopen (http://www.Baidu.com) ) )。
打印(resp.read ) )
其实,用浏览器浏览百度,右键点击源代码,你就会
帮我爬了百度首页的所有代码。
详细说明urlopen函数
1、url :请求的url、
2、data :请求的data,如果设置了该值
3、返回值:返回值为http.client.HttpResponse对象
# encoding 3360 utf-8 fromurllibimportrequestfromurlibimportparse # URL retrieve函数用法# request.URL retrieve (3359 timg sa.URL retrieve image quality=80 size=b 9999 _ 10000 sec=1511283869079 di=da 3892 a 20 ff8B4 d 5500 I 2.12使用eswedeblecrnwrx.jpg '、' luban.jpg ' ) # urlencode函数# params={'name':'xfdch、' age':18, ' greet ' 3360 ' hello world ' } # result=parse.urlencode (params ) ) print(result ) ) URL='http://www.baidu.com/resp=request.urlopen(URL ) print (resp.read ) ) # parse_qs函数用法params={'name':'xfdch, ' age ' greet ' : ' hello world ' } QS=parse.urlencode (params ) print ) QS ) result=parse.parse_QS ) rint