《零基础入门学习Python》学习过程笔记【53如何用Python访问互联网】

xiaoxiao2021-02-27  122

urllib是包

模块在包中

函数在模块中

urllib=url(网页地址)+lib(library)

URL由三部分组成  协议://路径/文件

协议,例如:http

http默认端口号为80

1.如何访问互联网?

import  urllib.request  #导入request模块

response=urllib.request.urlopen("http://网页")  #打开网页,并获得网页类的对象

html=response.read() 读取网页

#print(html) 会输出2进制版的html代码

html=html.decode("utf-8")  #解码为utf-8

#print(html)这时候会输出网页的html代码

转载请注明原文地址: https://www.6miu.com/read-14553.html

最新回复(0)