Python 如何访问互联网?
Python把URL和lib组合成一个模块urllib在IDLE里面可以搜索:
可以看到urllib有四个模块:
urllib.request,urllib.error,urllib.parse,urllib.robotparser
测试使用urllib.request模块:
>>> import urllib.request
>>> response = urllib.request.urlopen("http://www.fishC.com")
>>> html = response.read()
>>> print(html)
打印出来的网页内容是二进制代码,对其进行转码得到整齐的网页代码:
>>> html = html.decode("utf-8")
>>> print(html)