Python如何进行编解码和查看网页状态的方法
1、用 import 导入我们urllib模块,具体代码为:import urllib.request这里我们使用这个模块当中的 request 功能

3、接下来我们首先查看网页的状态信息,并且打印出结果,代码如下:print(file.getcode())

4、file.geturl() 这个方法可以获取url地址 ,打印结果如图所示

6、同样 我们也可以把编码过的url进行解码,具体如下:url = urllib.request.unquote("http%3A//www.sina.com")print(url)打印后效果如图

7、整体代码总结:import urllib.requestfile = urllib.request.urlopen("http://www.sina.com")print(file.getcode())print(file.geturl())url = urllib.request.quote("http://www.sina.com")print(url)url = urllib.request.unquote("http%3A//www.sina.com")print(url)