Australian (ASX) Stock Market Forum

Downloading ASX Fundamentals from Yahoo Finance using Perl/Python

Joined
12 February 2014
Posts
138
Reactions
25
Another project I've been working on is downloading fundamental data from Yahoo Finance using either Perl or Python. This is a 2 step process as outlined below:

1) First thing we need to do is create and populate a file called "symlist.csv" with symbols such as BHP.AX, ANZ.AX, etc. This can be done manually or you can use either perl script "asxsymlist.pl" or python script "asxsymlist.py" from attached zip file to populate the file. These scripts download the ASX symbols from the ASX website. If you want to use symbols from other stock exchanges then you will need to find some other way to populate the file.

2) Once the file "symlist.csv" has been populated, you can either use perl script "yhfund.pl" or python script "yhfund.py" to download fundamental data from yahoo finance. The results are stored in a comma seperated file called "yhfund.csv".

After you have got a feel for how things are done, you will need to edit the yhfund script to get the data you want. At the top of the file is a variable called "tags" which instructs the script what data you want to download such as P/E ratio. You may need to look up the tags available for yahoo finance to get what you want. The second thing you need to change is the variable "header" as this is written to the top of the csv file so that you know what data you're looking at when you view file "yhfund.csv".

Attached is zip file "yhfund20150502.zip" which contains the scripts "asxsymlist.pl, asxsymlist.py, yhfund.pl and yhfund.py". pl means perl script and py means python script, so you only need to run 2 scripts :)

Note: You do need to be connected to the internet :banghead:

Cheers,

Andrew.
 

Attachments

  • yhfund20150502.zip
    3.7 KB · Views: 106
So if you have perl installed, from the command line where you stored the above files, you first need to do the following:

yhfund_02_01.PNG

and this would create the file "symlist.csv" containing symbols/stock codes (over 2000) like so:

ANZ.AX
BHP.AX
CBA.AX

After checking the file, you then need to do the following:

yhfund_02_02.PNG

So what we are doing here is grabbing the symbols/stock codes from file "symlist.csv" and adding them to the url request along with tags. We do this a maximum of 200 stock codes per url request as this is the maximum yahoo will allow. So when the script is finished, the file "yhfund.csv" is created and populated with the all the fundamentals that the user specified in the tags variable of the script.
 
If you have python installed, from the command line where you stored the above files, you first need to do the following:

yhfund_03_01.PNG

And this also creates the exact same file "symlist.csv" containing symbols/stock codes (over 2000) like so:

ANZ.AX
BHP.AX
CBA.AX

After checking the file, you then need to do the following:

yhfund_03_02.PNG

and as described in the post above, the file "yhfund.csv" is created and populated with the all the fundamentals that the user specified in the tags variable of the script.
 
And here is what the file "yhfund.csv" should look like when viewed with a spread sheet application:

yhfundcsv_04_01.jpg

The above picture is a result of the scripts run in Linux Mint 13 and then viewing "yhfund.csv" using LibreOffice :). In windows (as shown in previous posts), you would use excel. As you can see from the bottom of my first post, you need to modify the tags variable in the script for the fundamental data you want and the header variable to tell you what you're looking at each time you run the script.
 
Top