1

I am trying to download a CSV file from morningstar using python. here is the link: http://financials.morningstar.com/income-statement/is.html?t=NAB&region=aus

There is a button to "export CSV" but I can't access the link.

There is this javascript:exportKeyStat2CSV(); but I am not sure how to find the URL of the CSV file?

I tried to download the file and get the URL to use requests/panadas to download the file but requests/panadas cant get anything.

import pandas as pd
URL= ("http://financials.morningstar.com/finan/ajax/exportKR2CSV.html?&callback=?&t=XASX:NAB&region=aus&culture=en-US&cur=&order=asc")

df=pd.read_csv(URL) ( didnt work with pandas)


import requests

print ('Starting to Download!')


r = requests.get(URL)

filename = url.split('/')[-1]

with open(filename, 'wb') as out_file:
    out_file.write(r.content)

print("Download complete!")

I get Requests 204 code.

How do I solve the problem?

Mort
  • 3,379
  • 1
  • 25
  • 40
Resa301
  • 15
  • 5

1 Answers1

0

Have you tried accessing the resource via Selenium with Python?

See this example: https://stackoverflow.com/a/51725319/5198805

Ryu S.
  • 1,538
  • 2
  • 22
  • 41