今天在抄写一段代码的时候,一个简单的爬虫,不太懂,就一句一句的查,查出了很多不会的地方,作个记录吧还是,首先把代码贴上来
#-*-coding:utf-8-*-
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',
process = firstLast):
try:
retval = urlretrieve(url)[0]
except IOError:
retval = None
if retval:
process(retval)
if __name__== '__main__':
download()
首先不懂得就是urlretrieve(url)这个方法,查了一下