Last active
October 25, 2015 06:20
-
-
Save eldritchideen/b2bfffd5cf625cc0ed3b to your computer and use it in GitHub Desktop.
Scrape list of stocks making up the All Ordinaries index.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Comparing scraping some simple data using both NodeJS and Python.