2011-07-28 26 views
0

以下のコマンドを使用してデータをダウンロードしようとしています。urllib.urlretrieveが失敗しています

import urllib 
url = 'http://www.nse-india.com/content/historical/EQUITIES/2002/MAR/cm01MAR2002bhav.csv.zip' 
urllib.urlretrieve(url, 'myzip') 

What I see in the file generated file my.zip is, 

You don't have permission to access "http&#58;&#47;&#47;www&#46;nse&#45;india&#46;com&#47;content&#47;historical&#47;EQUITIES&#47;2002&#47;MAR&#47;cm01MAR2002bhav&#46;csv&#46;zip" on this server.<P> 
Reference&#32;&#35;18&#46;7d427b5c&#46;1311889977&#46;25329891 

しかし、私はこの理由は何の問題 せずにWebサイトからファイルをダウンロードすることができますよ。

答えて

0

urllib2を使用し、user-agentヘッダーを認識するように設定する必要があります。通常のユーザーではないようなものはブロックしている可能性があります。

+0

Mozillaのようにuser-agentを試しても同じ問題があり、[link](http://code.activestate.com/recipes/572202-web-browser-emulator/)を使ってみましたが、余分なバイト数でダウンロードされますが、それは壊れています。 – kanna

+0

コードではなく、そのレシピから他のヘッダーを使用してみてください。 – agf

関連する問題