第三方提供函数库urllib和webbrowser使用,urllib访问网页,webbrowser调用浏览器,对浏览器进行操作。
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import urllib
>>> import webbrowser
>>> url = 'http://www.163.com'
>>> content = urllib.urlopen(url).read()
>>> print content
#打印content(http://www.163.com)内容,很长
>>>
>>> open('163.com.html','w').write(content) #保存content到当前目录下,文件名为163.com.html
>>> webbrowser.open_new_tab('163.com.html)
SyntaxError: EOL while scanning string literal
>>> webbrowser.open_new_tab('163.com.html') #打开本地163.com.html
True
>>> webbrowser.open_new_tab('http://www.huawei.com') #打开http://www.huawei.com
True
>>>
转载请注明原文地址: https://ju.6miu.com/read-38484.html