1、爬网页到本地
>>> import urllib.request
>>>urllib.request.urlretrieve("http://www.hellobi.com",filename="D:/Python代码/10.html")
('D:/Python代码/10.html', <http.client.HTTPMessage object at 0x0000000003719320>)
2、urllib.request.urlcleanup() 清除缓存
3、
>>> file=urllib.request.urlopen("http://www.hellobi.com")
>>> file.info()
<http.client.HTTPMessage object at 0x00000000037198D0>
>>> file.getcode()
200
>>> file.geturl()
'https://www.hellobi.com/'
4、超时设置
超过多长时间没查询到,则判断为无法打开网页
5、自动模拟HTTP请求
打开D:/Python代码/10.html即可打开在百度浏览器上搜索相应关键字的界面。
→
打开D:/Python代码/11.html即可打开在网页上显示如右上界面。