Parsing HTML
Today I wrote a bit of code to parse the ASX website for our latest stock price information at work. It’s really easy and the ASX is fine with it provided you reference the data and advise readers that there’s a 20 minute delay on the data.
Here’s how I did it:
This is the page we have to parse: http://www.asx.com.au/asx/markets/equityPrices.do?by=asxCodes&asxCodes=nvt
I used this simple HTML DOM Parser to make life easy: http://simplehtmldom.sourceforge.net/
This is the code:
< ?php include_once('simple_html_dom.php');
function scraping_asx() {
$html = file_get_html('http://www.asx.com.au/asx/markets/equityPrices.do?by=asxCodes&asxCodes=nvt');
foreach($html->find('table[class=datatable]') as $data) {
$item['last'] = trim($data->find('td', 0)->plaintext);
$item['change'] = trim($data->find('td', 1)->plaintext);
$item['volume'] = trim($data->find('td', 7)->plaintext);
}
$html->clear();
unset($html);
return $item;
}
$scrape = scraping_asx();
?>
<html>
<head>
<title>Stock Price</title>
<style type="text/css">
div#stock{
border:1px solid;
width:130px;
padding-left: 10px;
}
</style>
</head>
<body>
<div id="stock">
<p id="stock_price"> Price: <? echo $scrape['last']?></p>
<p id="stock_change"> Change: <? echo $scrape['change']?></p>
<p id="stock_volume"> Volume: <? echo $scrape['volume']?></p>
</div>
</body>
</html>
I’m aware that the foreach loop probably isn’t necessary, but I’m ok with it.
HTML parsing is neat. I’ll probably toy with it a lot more doing some iPhone or simple web app dev in future.
November 17, 2009 at 7:53 pm | Technology | No comment
Immorality before we die?
Article: Immortality only 20 years away says scientist
Ray Kurzweil thinks improving technology and a deeper understanding of how the human body works will improve everything from our physical abilities to our mental capacity by repairing and enhancing our organs using nanobots.
The world is changing so quickly that every day brings a new miracle. Never stop inventing!
November 5, 2009 at 10:36 pm | Life | No comment
Plannet Spotter
Link: Super-Earth shortens odds on finding life
Exciting that we found another earth like planet. Disappointing because the -200C to 2000C daily temperature range would make landing there difficult. When you think about it, life on earth is horribly fragile. Keep looking fellas!
September 17, 2009 at 5:54 pm | Life | No comment
Never looking back
Article: A One-Way Ticket to Mars
Human space travel is so expensive and so dangerous that we are going to need novel, even extreme solutions if we really want to expand the range of human civilization beyond our own planet. To boldly go where no one has gone before does not require coming home again.
A really interesting piece on some of the problems associated with sending a maned mission to Mars. The point raised is why is it so important to bring the astronauts home again? Plenty of people are willing to go even with no chance of ever returning.
Thinking about this put me in a highly reflective mood. In order to go where we’ve never gone before, do what we’ve never done before and truly change the world, maybe we need to take steps so drastic that the possibility of return doesn’t exist at all. Success and failure measured in the legacy we leave behind.
September 5, 2009 at 12:44 am | Life | No comment
Considering pretty women
Article: Men lose their minds speaking to pretty women.
Psychologists at Radboud University in The Netherlands carried out the study after one of them was so struck on impressing an attractive woman he had never met before, that he could not remember his address when she asked him where he lived.
Researchers said it was as if he was so keen to make an impression he ‘temporarily absorbed most of his cognitive resources.’
I continue to stand by my arguments in favour of considering cognitive load as a massive factor in application design.
What’s wrong with the news
Aritcle: The 3 key parts of news stories you usually don’t get
A really interesting read on the problems with journalism at the moment. It highlights that news reporting features only the latest headlines skipping over the important investigative details and relative backstory.
August 24, 2009 at 12:45 pm | Life | No comment
On the App Store
There’s been a constant buzz of internet activity circulating around the iTunes App Store recently with particular focus on app rejections and Apple’s responses. I don’t have a problem with apps being reviewed. I don’t have a problem with some apps being rejected. What I don’t like is that the rules for rejecting apps are vague at best and that some of them are down right stupid.
The one that really bugs me is the “duplicating functionality” argument. If google can build a better mail client than Apple can then why am I not entitled to decided which mail client I use? Same goes for browsers and everything else said to be duplicating functionality.
Apple, regarded by many as the most innovative company in the world, is doing nothing other than killing innovation by persisting with this non-compete policy.
August 24, 2009 at 11:28 am | iPhone | No comment
Archives by Category
- Design (5)
- Invignation (1)
- iPhone (3)
- Life (17)
- Social Media (3)
- Technology (6)
- Twitter (1)
- Uncategorized (2)
- Usability (1)
Archives by Month
- March 2010 (1)
- February 2010 (5)
- January 2010 (1)
- November 2009 (2)
- September 2009 (3)
- August 2009 (11)
- July 2009 (14)