Skip to main content
Message Font: Serif | Sans-Serif
No. of Recommendations: 1
I wasn't aware of advFN until Sand105 pointed it out (thanks Sand!). I may write a little "scraper" to grab data off advFN pages. A cursory look seemed to provide all the basic income, cash, and balance data.

The add-in used by Sand105's template is open-source, so that should make it easy to do so.

I use a quick-and-dirty PHP routine to grab the data, since AdvFN has it in 5-period chunks. For example:

"per=a" gives you annual periods; "per=q" gives you quarterly periods
"get=20" gets you 20 periods, you can get as many as they have available, but more take longer
"wb=y" places the output into EXCEL; "wb=n" displays in in the browser
"sym=" specifies the ticker symbol

The PHP code isn't all that complicated:

include 'subroutines.php';

$sym = isset($_GET['sym']) ? $_GET['sym'] : 'MMM';
$per = isset($_GET['per']) ? $_GET['per'] : 'q';
$get = isset($_GET['get']) ? $_GET['get'] : 999;
$wb = isset($_GET['wb']) ? $_GET['wb'] : 'n';
$btn = ($per == 'q') ? 'quarterly' : 'annual';
$start = ($per == 'q') ? '&istart_date=' : '&start_date=';
$url = ''.$btn
. '_reports&symbol='.$sym;

$data = file_get_contents($url);
$pattern = '/value=\'(.*?)\' selected>/';
preg_match_all($pattern, $data, $matches);
$ndx = $matches[1][1] + 4;
$beg = $ndx - $get + 1;
if ($beg < 0) $beg = 0;

$html = '<b->Ticker: '.$sym.'</b-><hr><table><tr>';
for($ptr = $beg; $ptr <= $ndx; $ptr = $ptr + 5) {
$data = file_get_contents($url.$start.$ptr);
$data2 = fExtr($data, -1, '>INDICATORS<', 1, '>INDICATORS<');
$html .= '<td>'.$data2.'</td>';

if ($wb == 'y') header('Content-Type: application/');
echo $html.'</tr></table>';
Note the "<b->" and "</b->" that need to be fixed because of TMF markup when I posted. I believe the fExtr() function is the only one used from the included subroutine library:

//* Finds start or end of HTML table by <TABLE or </TABLE tags
function fTable($data, $which, $dir, $find) {
$len = strlen($data);
$datac = strtoupper($data);
$datar = strrev($datac);
$pos = strpos($datac, strtoupper($find));
$which = strtoupper($which);
switch(TRUE) {
case ($which == "<TABLE" && $dir < 0): $offset = -6; break;
case ($which == "<TABLE" ): $offset = 0; break;
case ($which == "</TABLE" && $dir > 0): $offset = 8; break;
case ($which == "</TABLE" ): $offset = 0; break;
while ($dir > 0):
$pos = strpos($datac, $which, $pos) + $offset;
$dir = $dir - 1;
while ($dir < 0):
$pos = $len - strpos($datar, strrev($which), $len - $pos) + $offset;
$dir = $dir + 1;
return $pos;

//* Extracts a table from a web page
function fExtr($data, $dir1, $find1, $dir2, $find2) {
$pos1 = fTable($data, "<TABLE", $dir1, $find1);
if ($find2 == '') $find2 = $find1;
$pos2 = fTable($data, "</TABLE", $dir2, $find2);
return substr($data, $pos1, $pos2 - $pos1);
I had someone ask to do something similar for the financial statements on Fidelity (which they use for "Magic Formula" calculations):
Print the post  


What was Your Dumbest Investment?
Share it with us -- and learn from others' stories of flubs.
When Life Gives You Lemons
We all have had hardships and made poor decisions. The important thing is how we respond and grow. Read the story of a Fool who started from nothing, and looks to gain everything.
Contact Us
Contact Customer Service and other Fool departments here.
Work for Fools?
Winner of the Washingtonian great places to work, and Glassdoor #1 Company to Work For 2015! Have access to all of TMF's online and email products for FREE, and be paid for your contributions to TMF! Click the link and start your Fool career.