[英]Downloading all available CSV & KML files from the specific website
我正在尝试使用 python 来自动化从 data.gov.sg 下载所有可用 CSV 和 KML 文件的过程。 但是,我们收到了“HTTP 错误 403:禁止”错误消息。 我们曾经遇到过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)
HTTP 403 错误http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.4表示您已被禁止访问,要么您需要授权访问此权限,要么服务器管理员已阻止您访问它并发送 403 响应作为通知。
因此,我可以看到您的代码没有任何问题(尽管您似乎丢失了缩进),这会导致此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.