1 <? 建议使用 <?php 2 Function 建议使用 function其它的,建议你把出错信息贴出来...
解决方案 »
- 求救:关于PHP的SSH2
- 为什么我的memcached win 安装不成功
- ◆ ◆ ◆ 跟别人争论PHP中MVC的问题,真的有些累了。。。。 ◆ ◆ ◆
- 请教,怎么能让php页面不去等待system所调用的命令的返回结果?
- 新手分享-数据查询结果按字段排序函数代码
- How to call the function in the Class File
- 请问,select出符合所有条件记录后,想随机显示其中数条,怎么弄?谢谢
- 关于对文件操作的问题!
- 关于.htaccess设置
- 关于mac 搭建环境的问题,请各路大神指点一下
- 一个基于php+access的完整/整站程序[可以在线看效果]
- 如何实现静态网页中使用动态生成部分内容
不要用固定的标签字串,
解析HTML标签,这样更准确。
lz看看解析HTML的函数库吧,这里是采集的关键。
http://php-html.sourceforge.net/
看上去很乱.另外,哪里出错,有什么错误提示.
//获取网页内容
Function fetch_urlpage_contents($url){
for($i=0;$i<10;$i++)
{
$c=@file_get_contents($url);
if(trim($c) != "")break;
}
// print($c);
return $c;
}//获取匹配内容
Function fetch_match_contents($begin,$end,$c)
{
$beginPos = strpos($c,$begin);
$endPos = strpos($c,$end);
if($beginPos > 0 && $endPos > 0 && $endPos > $beginPos)
{
$result = substr($c,$beginPos+strlen($begin),$endPos - $beginPos-strlen($begin));
return $result;
}
else
{
return "";
}
} //采集网页
Function pick($url,$ft,$th)
{
$c=fetch_urlpage_contents($url);
foreach($ft as $key => $value)
{
$rs[$key]=fetch_match_contents($value["begin"],$value["end"],$c);
if(is_array($th[$key]))
{ foreach($th[$key] as $old => $new)
{
$rs[$key]=str_replace($old,$new,$rs[$key]);
}
}
}
return $rs;
}
?><html>
<title>caiji</title>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<?$url="http://www.01job.cn/asp/itjob.asp";
$ft["title"]["begin"]="<title>";
$ft["title"]["end"]="</title>";
$rs=pick($url,$ft,$th);
print_r($rs);
?>
</body>
</html>
preg_match_all('/<a .*? class="Pos">(.*)<\/a>/',$content,$arr);
print_r($arr);
$con .= file_get_contents("http://newhouse.hfhouse.com/HouseList/index/areaId/4/?&p=$i");
$preg = '#<td width="130" rowspan="5" align="center" valign="middle" id="(.*)"><a href="(.*)" target="_blank"><img src="(.*)" alt="(.*)" width="124" height="98" hspace="3" vspace="3" border="0" /></a></td>#iUs';
preg_match_all($preg , $con , $arr);
print_r($arr[4]);
这种方法只能采集一页,我要采集多个列表页,如何修改代码呢?