I'm using this code:
$url = 'http://www.publicwhip.org.uk/mp.php?mpn=' . $avariable . '&mpc=' . $anothervariable . '&house=commons&display=everyvote#divisions';
$options = array('http' => array('header' => "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.125 Safari/533.4"));
$context = stream_context_create($options);
$html = file_get_html($url, false, $context);
foreach($html->find('table.votes tr.odd,tr.even') as $tr) {
if ($tr->find('td', 3) == '<td>absent</td>') { $voted = $voted + 1; }
$possible = $possible + 1;
}
I'm getting the correct values for some of the pages such as
http://www.publicwhip.org.uk/mp.php?mpn=Flick_Drummond&mpc=Portsmouth_South&house=commons&display=everyvote#divisions
and
http://www.publicwhip.org.uk/mp.php?mpn=Kelly_Tolhurst&mpc=Rochester_and_Strood&house=commons&display=everyvote#divisions
but when I reached
http://www.publicwhip.org.uk/mp.php?mpn=Jim_Dowd&mpc=Lewisham_West_and_Penge&house=commons&display=everyvote#divisions
or
http://www.publicwhip.org.uk/mp.php?mpn=Tom_Watson&mpc=West_Bromwich_East&house=commons&display=everyvote#divisions
it gives me 0 when there are several values that should be counted.
I've looked at each page's layout and they are all the same so I'm stumped as to why it's returning 0 on some pages.
EDIT:
when I remove the check
if($html && is_object($html) && isset($html->nodes))
it returns
Fatal error: Call to a member function find()
I don't understand this as all 4 pages I mentioned above have similar structures