python练习 抓取web页面
时间:2010-09-25 来源:night85
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://search.51job.com/jobsearch/advance_search.php',process=firstLast):
try:
retval = urlretrieve(url) [0]
except IOError:
retval = None
if retval:
process(retval)
if __name__ == '__main__':
download()
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://search.51job.com/jobsearch/advance_search.php',process=firstLast):
try:
retval = urlretrieve(url) [0]
except IOError:
retval = None
if retval:
process(retval)
if __name__ == '__main__':
download()
相关阅读 更多 +