httplib2

爬虫:从某个网站上下载一个网页,并在自己的主机上自动打开浏览器浏览。

copy网上的代码,运行提示,***函数没有定义,可能是因为没有下载其使用的第三方函数库并安装

linux下安装第三方函数库

easy_install httplib2

eg:

>>> import urllib---------urllib可以访问公网的网页
>>> import webbrowser as web---------------webbrowser是第三方的
>>> url="http://www.163.com"---------------要登录的url
>>> content=urllib.urlopen(url).read()-----获取首页
>>> open("robin.html").write(content)-如果文件存在则打开,不存在则新建,然后写入变量内容,存到本地,名字为robin.html

>>> web.open_new_tab('robin.html')------通过浏览器打开,浏览



web.open_new_tab('http://www.baidu.com')  也可以独立使用,调用浏览器

使用第三方函数库的方法

module_name.method(参数)

eg:urllib.urlopen().read()

    webbrowser.open_new_tab()