Skip to content

Instantly share code, notes, and snippets.

@eldritchideen
Last active October 25, 2015 06:20
Show Gist options
  • Save eldritchideen/b2bfffd5cf625cc0ed3b to your computer and use it in GitHub Desktop.
Save eldritchideen/b2bfffd5cf625cc0ed3b to your computer and use it in GitHub Desktop.
Scrape list of stocks making up the All Ordinaries index.
const request = require('request'),
cheerio = require('cheerio'),
fs = require('fs');
request('http://www.marketindex.com.au/all-ordinaries', function (error, response, body) {
if (!error && response.statusCode === 200) {
let stocks = [];
let $ = cheerio.load(body);
$('#asx_sp_table > tbody > tr > td:nth-child(2)').each((i,elem) => {
stocks[i] = elem.children[0].data;
});
console.log('Fetched ' + stocks.length + ' stocks.');
console.log(stocks.join(','));
fs.writeFileSync('all-ords.txt', stocks.join('\n'), 'utf8');
}
});
import requests
from bs4 import BeautifulSoup
response = requests.get("http://www.marketindex.com.au/all-ordinaries")
soup = BeautifulSoup(response.text, 'html.parser')
f = open("all-ords.txt", "w")
for row in soup.select("#asx_sp_table > tbody > tr"):
tds = row.find_all("td")
code = tds[1].text.strip()
name = tds[2].text.strip()
f.write("{0}.AX\t{1}\n".format(code, name))
f.close()
@eldritchideen
Copy link
Author

Comparing scraping some simple data using both NodeJS and Python.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment