Home > php教程 > php手册 > body text

PHP实现抓取网页的所有超链接的代码

WBOY
Release: 2016-06-21 08:57:22
Original
931 people have browsed it

因为最近要做一个类似专业搜索引擎的东西,需要抓取网页的所有超链接。大家帮忙测试一下子,下面的代码是否可以针对所有的标准超链接。

通用HTML标准超链接参数取得正则表达式测试

因为最近要做一个类似专业搜索引擎的东西,需要抓取网页的所有超链接。
大家帮忙测试一下子,下面的代码是否可以针对所有的标准超链接。

测试代码如下:
 

// --------------------------------------------------------------------------

// File name   : Noname1.php
// Description : 通用链接参数获取正则表达式测试
// Requirement : PHP4 (http://www.php.net)
// Copyright(C), HonestQiao, 2005, All Rights Reserved.
// Author: HonestQiao (honestqiao@hotmail.com)
// 参数说明:
// $strSource: 包含标准链接的HTML网页
// $strResult: 处理的结果
// 附加说明:
// 标准链接,使用形势包含的链接
// --------------------------------------------------------------------------
$strSource = t1
t2
t3
t4
HTML;
preg_match_all('/(.+?)/sim', $strSource, $strResult, PREG_PATTERN_ORDER);
for($i = 0; $i {
    printf("%d href=(%s) title=(%s) \n", $i, $strResult[1][$i], $strResult[2][$i]);


?>
Copy after login



如果您的测试数据,符合标准链接,但是此处没有被处理出来,请告诉我测试数据,以及你的测试环境。

谢谢。
 



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!