0

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)
2
  • Indentation level at function rciveURL() seems wrong. Is it just a typo? Commented Jun 26, 2016 at 17:20
  • As noted, your code isn't formatted properly. Also, requests is a third party replacement for the standard urllib. So pick which one you want. Requests is easier to understand Commented Jun 26, 2016 at 17:25

1 Answer 1

1

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.