检查链接是否通过python urllib2重定向到标准页面

时间:2013-06-17 11:49:52

标签: python csv web-scraping screen-scraping urllib2

我正在尝试通过循环检查所有链接有效哪些无效并重定向到某个标准页面

import urllib2
import csv



i=18509
yyy = csv.writer(open('valid_links.csv', 'w'), delimiter=',',quotechar='"',lineterminator="\n")

while i!=0:
   print i
   url="http://investing.businessweek.com/research/stocks/private  /snapshot.asp?privcapId="+str(i)
   request = urllib2.Request(url)
   request.get_method = lambda : 'HEAD'
   response = urllib2.urlopen(request)
   it=response.info()

   #page = urllib2.urlopen(url,timeout=2).geturl()
   yyy.writerow([url,it['Content-Length']])
   i=i+1

我有200多万页要检查,有没有更有效的方法?

0 个答案:

没有答案