您的位置:首页 > 运维架构 > 网站架构

公司网站首页遇到的问题

2015-10-07 20:50 666 查看
urllib参考:
http://www.cnblogs.com/sysu-blackbear/p/3629420.html

1.urllib.urlopen(url[,data[,proxies]])

打开一个url的方法,返回一个文件对象,然后可以进行类似文件对象的操作。本例试着打开google

>>> import urllib
>>> f = urllib.urlopen('http://www.google.com.hk/')
>>> firstLine = f.readline()   #读取html页面的第一行
>>> firstLine
'<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage"><head><meta content="/images/google_favicon_128.png" itemprop="image"><title>Google</title><script>(function(){\n'

urlopen返回对象提供方法:

- read() , readline() ,readlines() , fileno() , close() :这些方法的使用方式与文件对象完全一样

- info():返回一个httplib.HTTPMessage对象,表示远程服务器返回的头信息

- getcode():返回Http状态码。如果是http请求,200请求成功完成;404网址未找到

- geturl():返回请求的url

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: