Fetch codes of all companies making up the All Ords Index


In [2]:
from datetime import datetime
import urllib.request
import urllib.response
from bs4 import BeautifulSoup

In [3]:
url = "http://www.marketindex.com.au/all-ordinaries"
resp = urllib.request.urlopen(url)
soup = BeautifulSoup(resp.read(), 'lxml')

In [5]:
table = soup.select("#asx_sp_table > tbody > tr")

In [28]:
all_ords_codes = [row.contents[3].text for row in table ]

In [29]:
with open("all_ords.txt", "w") as f:
    for code in all_ords_codes:
        f.write(code + "\n")

In [ ]: