首页 > 编程知识 正文

python urllib3,urlopen函数作用

时间:2023-05-06 20:34:10 阅读:24465 作者:2972

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

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。