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.
Google’s New Search Engine
Link: New Google Search Test
Turns out Google haven’t just been kicking back counting the dollars, they’ve been working on a better Google. The new backend system brings faster searches along with quicker indexing and a host of other upgrades. You can test the new search here.
BusyCal: iCal Done Better
Link: BusyCal
It’s not perfect but it fixes a lot of the little annoyances in iCal. Syncs with Google well too. Free during beta.
Much love to Fake Steve
Link: Borg-funded hate campaign continues
I love this bit (in relation to iPods blowing up):
Also, frankly, you need to keep this “quality control” issue in perspective. Just remember: these things are assembled by seven-year-old children in China. It’s a miracle that any of them work at all.
Microsoft Stores
Article: Microsoft to Open Retail Stores Next to Apple’s
Microsoft is planning to open their own retail stores next to Apple’s retail stores. They weren’t commenting on how they will look except to say that they’ll be “innovative”. If Microsoft’s current ads are anything to go by I expect they’ll look cheap.
Dell Planning a (Probably Horrible) Smartphone
Article: Delusional Dell Planning a Smartphone
Dell’s apparently planning to make a smartphone. History shows that all Dell’s ventures into hand held products have failed miserably. I’m expecting a similar outcome in this case, especially if they go with Windows Mobile in typical Dell style.
“Who actually makes the hardware, the software, or manufactures the specific designs — I don’t really believe that any of the operators globally care how we execute that,” Garrique said. “What they want us to do is be an integrator and provide them a solution on the consumer side.”
Yes! Lets build a phone for operators which integrates parts that don’t really matter! I’m sure that device will be real consumer friendly.