【发布时间】:2015-11-24 02:09:35
【问题描述】:
我正在尝试使用 python 来自动化从 data.gov.sg 下载所有可用的 CSV 和 KML 文件的过程。但是,我们收到了“HTTP Error 403: Forbidden”错误消息。我们曾经得到一个已经解决的 robots.txt 错误。我们下面的编码有什么问题吗?
import mechanize
from time import sleep
br = mechanize.Browser()
br.open('https://data.gov.sg/')
f=open("source.html","w")
f.write(br.response().read())
f.close()
filetypes=[".csv",".kml"]
myfiles=[]
for l in br.links():
for t in filetypes:
if t in str(l):
myfiles.append(l)
def downloadlink(l):
f=open(l.text,"w")
br.click_link(l)
f.write(br.response().read())
f.close()
print l.text," has been downloaded"
#br.back()
for l in myfiles:
sleep(1)
downloadlink(l)
【问题讨论】: