php blog 抓取匹配xml

wanglinmingtina 2010-07-20 04:34:24
如何从抓取的页面中匹配下面的内容
<link rel="alternate" type="application/rss+xml" href="http://blog.sina.com.cn/rss/lilianjie.xml" title="RSS" />

同时取出 href 的内容 一定要匹配 rel值 alternate type的值 application/rss+xml
...全文
119 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
leaffall 2010-07-21
  • 打赏
  • 举报
回复
最简单的办法是使用 simplehtmldom http://simplehtmldom.sourceforge.net/


// example of how to use basic selector to retrieve HTML contents
include('../simple_html_dom.php');
$string = <<<content
<link rel="alternate" type="application/rss+xml" href="http://blog.sina.com.cn/rss/lilianjie.xml" title="RSS" />
<ink rel="stylesheet" type="text/css" href="http://simg.sinajs.cn/blog7style/css/blog/newblog2.css" />
<br>
<div></div>
<lin REL="stylesheet" href="http://simg.sinajs.cn/blog7style/css/blog/newblog3.css" type="text/css"/>
<link Rel="Alternate" type="text/css" href="http://simg.sinajs.cn/blog7style/css/blog/newblog4.css" />
<link type="application/rss+xml" href="http://blog.sina.com.cn/rss/lilianjie24.xml" title="RSS" rel="alternate"/>
<link rel="Alternate" type="application/rss+xml" href="http://blog.sina.com.cn/rss/lilianjie22.xml" title="RSS" />
<link rel="alternate" href=http://blog.sina.com.cn/rss/lilianjie21.xml title="RSS" type='application/rss+xml'/>
<ink rel="stylesheet" type="text/css" href="http://simg.sinajs.cn/blog7style/css/blog/newblog5.css" />
<br>
<div></div>
<lin rel="stylesheet" type="text/css" href="http://simg.sinajs.cn/blog7style/css/blog/newblog6.css" />
content;

$html = str_get_html($string);

// find all link
foreach($html->find('link') as $e) {
if(strtolower($e->rel)=="alternate" && strtolower($e->type)=="application/rss+xml")
echo $e->href . '<br>';
}

amani11 2010-07-20
  • 打赏
  • 举报
回复
路过,看老大的代码留名
xuzuning 2010-07-20
  • 打赏
  • 举报
回复
不要在一棵树上吊死!
$string = <<<content
<link rel="alternate" type="application/rss+xml" href="http://blog.sina.com.cn/rss/lilianjie.xml" title="RSS" />
<link rel="stylesheet" type="text/css" href="http://simg.sinajs.cn/blog7style/css/blog/newblog.css" />
content;

$p = array('/<link\s+/i', '/" +/', '#/>#', '/"/', '/=/', "/[\r\n]+/");
$r = array('', '&', '', '', '[]=', '');

$s = preg_replace($p, $r, $string);

parse_str($s, $info);
print_r($info);

Array
(
[rel] => Array
(
[0] => alternate
[1] => stylesheet
)

[type] => Array
(
[0] => application/rss xml
[1] => text/css
)

[href] => Array
(
[0] => http://blog.sina.com.cn/rss/lilianjie.xml
[1] => http://simg.sinajs.cn/blog7style/css/blog/newblog.css
)

[title] => Array
(
[0] => RSS
)

)
wanglinmingtina 2010-07-20
  • 打赏
  • 举报
回复
请求帮助
wanglinmingtina 2010-07-20
  • 打赏
  • 举报
回复
$string = <<<content
<link rel="alternate" type="application/rss+xml" href="http://blog.sina.com.cn/rss/lilianjie.xml" title="RSS" />
<link rel="stylesheet" type="text/css" href="http://simg.sinajs.cn/blog7style/css/blog/newblog.css" />
content;

如果 要进行匹配的内容是 string , 我只想匹配 rel=alternate type=application/rss+xml 的标签 同时取得
href的值
CunningBoy 2010-07-20
  • 打赏
  • 举报
回复
$string = <<<content
<link rel="alternate" type="application/rss+xml" href="http://blog.sina.com.cn/rss/lilianjie.xml" title="RSS" />
<<<
preg_match_all('/<link rel=\"(.*)\" type=\"(.*)\" href=\"(.*)\"[^>]* \/>/is', $string, $matches);
print_r($matches);
yangball 2010-07-20
  • 打赏
  • 举报
回复

//未经测试。
preg_match_all('/<link\s+rel="alternate"\s+type="application/rss+xml".*\/>/i',$strimg,$matches);
var_dump($matches);
内容概要:本文围绕不确定环境下的多式联运路径优化问题展开研究,提出并实现了基于AFO算法、遗传算法(GA)和粒子群优化算法(PSO)的三种智能优化方法,并借助Matlab平台完成算法编程与仿真。研究构建了考虑时间、成本、转运风险等多重不确定因素的路径优化模型,系统比较了AFO、GA、PSO三种算法在收敛速度、全局寻优能力和稳定性方面的表现,同时引入Matlab自带的全局优化搜索器作为基准对照,深入分析各算法在复杂物流网络中的适用边界与性能差异。研究表明,AFO算法在解决此类组合优化问题时展现出更快的收敛效率和更强的局部规避能力。; 适合人群:具备一定Matlab编程基础与运筹优化知识,从事物流工程、交通运输规划、智能算法开发等相关领域的研究生、科研人员及工程技术人员。; 使用场景及目标:①应用于多式联运、综合货运网络中的路径决策支持系统构建;②为不确定性条件下复杂路径规划问题提供智能算法选型依据与技术实现方案;③支持科研人员复现主流优化算法并开展横向性能对比实验,推动算法改进与实际落地。; 阅读建议:建议读者结合提供的Matlab代码逐模块分析算法实现流程,重点理解目标函数设计、约束条件处理及参数敏感性分析部分,可通过调整问题规模与算法参数进行对比实验,进一步拓展至动态路径规划或大规模网络优化等延伸场景。

21,889

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧