php文章内容抓取
$url = 'http://sports.sohu.com/zhongchao.shtml';<br />$s = file_get_contents($url);<br />preg_match_all('/(?<=<div class="turn cons">)\s<table.+table>/isU', $s, $m);<br />print_r(preg_grep('/名次/', $m[0]));
Array<br />(<br /> [2] => <br /><table border=0 cellSpacing=0 cellPadding=0 width="100%"><br /><tbody><br /><tr><br /><th width="15%">名次</th><br /><th width="47%">球队</th><br /><th width="9%">场次</th><br /><th width="29%">积分</th></tr><br /><tr><br /><td>01</td><br /><td><a href="http://sports.sohu.com/s2010/7742/s277701524/" target="_blank">广州恒大</a></td><br /><td>20</td><br /><td>45</td><br /></tr><br /><tr><br /><td>02</td><br /><td><a href="http://sports.sohu.com/s2006/7742/s242155493/" target="_blank">北京国安</a></td><br />......接下来自己做
<br />include "simple_html_dom.class.php";<br /><br />$url = "http://sports.sohu.com/zhongchao.shtml";<br />$dom = new simple_html_dom();<br />$html = $dom->load(file_get_contents($url));<br /><br />$res = $html->find("div#turnIDB div.turn");<br /># 积分榜<br />echo $res[0]->outertext;<br /># 射手榜<br />echo $res[1]->outertext;<br />
$str=file_get_contents("http://sports.sohu.com/zhongchao.shtml");<br /><br />preg_match_all('/<tr>\s*<td>(.+?)<\/td>\s*<td>(.+?)<\/td>\s*<td>(\d+)<\/td>\s*<td>(.+?)<\/td>\s*<\/tr>/i',$str,$match1);<br /><br />foreach($match1 as $k=>$v){<br /> if($k!=0){<br /> foreach($v as $k1=>$v1){<br /> if($k1<=15){<br /> $jifen[$k][]=$v1;<br /> }else{<br /> $sheshou[$k][]=$v1;<br /> }<br /> }<br /> }<br />}<br />echo "<pre class="brush:php;toolbar:false">";<br />print_r($jifen);<br />print_r($sheshou);<br />echo "";