Python下载网页

想把POJ的所有题目下载下来,就用Python写了个小东西,分享一下,请大家指教~

 

from urllib import urlopenimport os.path
url = "http://poj.org/problem?id="

num = 2897

N=3982
if os.path.isdir(r"d:\download\POJ"):    

  pass

else:    

  os.mkdir(r"d:\download\POJ")
  while num <= N:   

  webdata = urlopen(url + str(num)).read()    

  print webdata    

  myfile = file(r"d:\download\POJ\poj"+ str(num) +".html",'w')    

  print >> myfile, webdata    

  myfile.close()   

   num += 1

posted @ 2010-12-05 22:46  excellentbright  阅读(480)  评论(0编辑  收藏  举报