#引入urllib库 (成功) |
#import urllib.request |
from urllib.request import urlopen #从某一模块指引入一个方法 |
#通过URL获取他的HTML代码 |
url = 'https://www.jd.com/get' |
#打开指定的URL,获取返回的内容放在response中 |
#response = urllib.request.urlopen(url) |
response = urlopen(url) #相对应的使用方法 |
#打印获取到的HTML,二进制表现形式 |
#print(response.read()) |
#字符转换 |
print (response.read().decode( 'utf-8' )) #将response中的内容读取并转码显示 |
#request的其他信息 |
print (response.geturl()) #打印其中的URL信息,这才是真是的URL信息(发给服务器的真实url) |
#request的头信息 |
print (response.info()) |
print (response.getheaders()) #与上一行作用相同,只是结果以不同的表现形式展示 |
print (response.getheader( 'server' )) #(查询头信息里的部分信息)查询网站的服务器信息 |
#BWS :百度、web、server |