python抓取WEB页面

songrongu111 2009-07-30 08:25:27
retval=urlretrieve(url)[0] 不知道是什么意思 能不能解释下


from urllib import urlretrieve

def firstNonBlank(lines):
for eachline in lines:
if not eachline.strip():
continue
else:
return eachline

def firstlast(webpage):
f=open(webpage)
lines=f.readlines()
f.close()
print firstNonBlank(lines),
lines.reverse()
print firstNonBlank(lines),


def download(url='http://www.xiaonei.com',
process=firstlast):

try:
retval=urlretrieve(url)[0]
except IOError:
retval=None
if retval:
process(retval)


if __name__=='__main__':
download()
...全文
217 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
songrongu111 2009-08-04
  • 打赏
  • 举报
回复
结贴了
BLwei 2009-08-04
  • 打赏
  • 举报
回复
retval=urlretrieve(url)[0]=(filename, headers)[0]=filename

guangboo 2009-08-04
  • 打赏
  • 举报
回复
学习了。
=====
http://www.klipdas.com
lioujian47 2009-08-03
  • 打赏
  • 举报
回复
这里看看
http://bbs.chinaunix.net/archiver/?tid-1029403.html
zouhailin 2009-08-03
  • 打赏
  • 举报
回复
这么强大
好好学学
evan007 2009-08-02
  • 打赏
  • 举报
回复
学习了,顶个
DarkChampion 2009-07-30
  • 打赏
  • 举报
回复
文档对urlretrieve返回的解释:
Copy a network object denoted by a URL to a local file, if necessary. If the URL points to a local file, or a valid cached copy of the object exists, the object is not copied.
Return a tuple (filename, headers) where filename is the local file name under which the object can be found, and headers is whatever the info() method of the object returned by urlopen() returned

就是说返回一个元组,第一个是缓存的本地文件名

37,721

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧