发布时间:2017-11-28 21:14:29编辑:Run阅读(4869)
URL的一般格式(带方括号[]的为可选项)
protocol://hostname[:port]/path/[;parameters][?query]#fragment
protocol 为协议:http,https,ftp,file,ed2k
hostname 为域名或者是ip地址
[port] 为可选参数 端口,一般http的默认端口为80,https为443
/path/ 为路劲,具体地址,如目录或者文件名等
import urllib.request 导入urllib.request模块
response = urllib.request.urlopen('URL') 打开目标网站,URL=目标网站地址
html = response.read() 读取一个网站
html = html.decode("utf-8") 解码为utf-8
一个完整实例
import urllib.request
response = urllib.request.urlopen('https://www.baidu.com')
html = response.read()
html = html.decode("utf-8")
print(html)
48114
46811
37732
35047
29588
26244
25172
20215
19854
18323
5993°
6679°
6172°
6160°
7271°
6109°
6217°
6694°
6660°
8055°