PHP实现抓取网页的所有超链接的代码
Jun 21, 2016 am 08:57 AM因为最近要做一个类似专业搜索引擎的东西,需要抓取网页的所有超链接。大家帮忙测试一下子,下面的代码是否可以针对所有的标准超链接。
通用HTML标准超链接参数取得正则表达式测试
因为最近要做一个类似专业搜索引擎的东西,需要抓取网页的所有超链接。
大家帮忙测试一下子,下面的代码是否可以针对所有的标准超链接。
测试代码如下:
<?php <br/>// -------------------------------------------------------------------------- <br>// File name : Noname1.php <br>// Description : 通用链接参数获取正则表达式测试 <br>// Requirement : PHP4 (http://www.php.net) <br>// Copyright(C), HonestQiao, 2005, All Rights Reserved. <br>// Author: HonestQiao (honestqiao@hotmail.com) <br>// 参数说明: <br>// $strSource: 包含标准链接的HTML网页 <br>// $strResult: 处理的结果 <br>// 附加说明: <br>// 标准链接,使用<a></a>形势包含的链接 <br>// -------------------------------------------------------------------------- <br>$strSource = <a>t1</a> <br><a>t2</a> <br><a>t3</a> <br><a>t4</a> <br>HTML; <br>preg_match_all('/<a.>(.+?)/sim', $strSource, $strResult, PREG_PATTERN_ORDER); <br>for($i = 0; $i { <br> printf("%d href=(%s) title=(%s) \n", $i, $strResult[1][$i], $strResult[2][$i]); <br>} <br> <br>?></a.>
Copy after login
如果您的测试数据,符合标准链接,但是此处没有被处理出来,请告诉我测试数据,以及你的测试环境。
谢谢。
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

Hot Article
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot tools Tags

Hot Article
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)
