Reputation:
i wana simply send a request to the following url and recive data in csv format and save on the following location,but doest not work!any help will be appreciated
from urllib import request
my_url='http://real-chart.finance.yahoo.com/table.csv?s=CSV&a=07&b=9& c=1996&d=05&e=26&f=2016&g=d&ignore=.csv'
def rciveURL(getURL):
response=request.urlopen(getURL)
csv=response.read()
csv_str=str(csv)
mydstination=r'mori.csv'
fx=open(mydstination,"w")
for line in csv_str:
fx.write(line+"\n")
fx.closed()
rciveURL(my_url)
Upvotes: 0
Views: 53
Reputation: 672
The correct way to receive a file from url
and save a file at save_dest
is:
import urllib
file = urllib.URLopener()
file.retrieve(url, save_dest)
Upvotes: 1