解析URL的网站 [英] Parse Website for URLs

查看:92
本文介绍了解析URL的网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是想知道是否有人可以帮助我进一步以下。我想解析这个网站上的URL:http://www.directorycritic.com/free-directory-list.html?pg = 1& sort = pr



我有以下代码:

 <?PHP 
$ url =http://www.directorycritic。 COM /自由目录-list.html PG = 1&安培;排序= PR;
$ input = @file_get_contents($ url)或死(无法访问文件:$ url);
$ regexp =< a \s [^>] * href =(\??)([^ \>] *?)\\1 [^> ] *><(。*); \ / A>中;
if(preg_match_all(/ $ regexp / siU,$ input,$ matches)){
// $ matches [2] =链接地址数组
// $ matches [3 ] =链接文本数组 - 包括HTML代码
}
?>

目前没有任何操作,我需要做的是将表格中的所有网址所有16页,并会真正感谢一些帮助,如何修改上述做到这一点,并输出到一个文本文件的URL。 HTML Dom Parser

  $ html = file_get_html('http://www.example.com/'); 

//查找所有链接
$ links = array();
foreach($ html-> find('a')as $ element)
$ links [] = $ element-> href;

现在links数组包含给定页面的所有URL,您可以使用这些URL进一步解析。 p>

使用正则表达式解析HTML并不是一个好主意。以下是一些相关的帖子:

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆