我正在使用此代码:
$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;
}
我为某些页面获取了正确的值,例如
http://www.publicwhip.org.uk/mp.php?mpn=Flick_Drummond&mpc=Portsmouth_South&house=commons&display=everyvote#divisions
和
http://www.publicwhip.org.uk/mp.php?mpn=Kelly_Tolhurst&mpc=Rochester_and_Strood&house=commons&display=everyvote#divisions
但是当我到达时
http://www.publicwhip.org.uk/mp.php?mpn=Jim_Dowd&mpc=Lewisham_West_and_Penge&house=commons&display=everyvote#divisions
或
http://www.publicwhip.org.uk/mp.php?mpn=Tom_Watson&mpc=West_Bromwich_East&house=commons&display=everyvote#divisions
当有几个值应计算时,它给出0。
我查看了每个页面的布局,它们都是一样的,所以我很难过为什么它会在某些页面上返回0。
编辑:
我删除支票
if($html && is_object($html) && isset($html->nodes))
它返回
Fatal error: Call to a member function find()
我不明白这一点,因为我上面提到的所有4页都有类似的结构