}
curl_close($ch);
$linkarr = _striplinks($html);
// 主机部分,补全用
$host = '';
if (is_array($linkarr)) {
foreach ($linkarr as $k = $v) {
$linkresult[$k] = _expandlinks($v, $host);
}
}
printf("p此页面的所有链接为:/ppre%s/pren", var_export($linkresult , true));
?
function.php内容如下(即为上两篇中两个函数的合集):
?php
function _striplinks($document) {
preg_match_all("'s*as.*?hrefs*=s*(["'])?(?(1) (.*?)\1 | ([^s]+))'isx", $document, $links);
// catenate the non-empty matches from the conditional subpattern
while (list($key, $val) = each($links[2])) {
if (!empty($val))
$match[] = $val;
} while (list($key, $val) = each($links[3])) {
if (!empty($val))
$match[] = $val;
}
// return the links
return $match;
}
/*===================================================================*
Function: _expandlinks
Purpose: expand each link into a fully qualified URL
Input:$linksthe links to qualify
$URIthe full URI to get the base from
Output:$expandedLinks the expanded links
*===================================================================*/
function _expandlinks($links,$URI)
{
$URI_PARTS = parse_url($URI);
$host = $URI_PARTS["host"];
preg_match("/^[^?]+/",$URI,$match);
$match = preg_replace("|/[^/.]+.[^/.]+$|","",$match[0]);
$match = preg_replace("|/$|","",$match);
$match_part = parse_url($match);
$match_root =
$match_part["scheme"]."://".$match_part["host"];
$search = array("|^http://".preg_quote($host)."|i",
"|^(/)|i",
"|^(?!http://)(?!mailto:)|i",
"|/./|",
"|/[^/]+/../|"
);
$replace = array( "",
$match_root."/",
$match."/",
"/",
"/"
);
$expandedLinks = preg_replace($search,$replace,$links);
return $expandedLinks;
}
?
php在线采集网页数据库的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于php采集系统、php在线采集网页数据库的信息别忘了在本站进行查找喔 。
推荐阅读
- python爬虫带验证码实例,python爬虫 验证码
- 关于为什么喜欢看肢解视频的信息
- 如何关闭毒霸pdf,如何关闭毒霸
- 网赚平台代理,网站代理赚钱
- Python下载函数包 python下载函数库
- sap中的模块,sap各模块
- 如何加入百度推广答案,如何在百度推广项目
- vps拨号服务器,vps拨号服务器哪家好
- java代码是否回文 java 回文