从没有rss feed的外部站点提取最新新闻-preg_match()? [英] Pull recent news items from external site with no rss feed - preg_match()?

查看:62
本文介绍了从没有rss feed的外部站点提取最新新闻-preg_match()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试从此处从此站点获取最新的4条新闻: http://www.wolverinegreen .com/sports/m-wrestl/spec-rel/utva-m-wrestl-spec-rel.html

I am trying to pull the latest 4 news items from this site here: http://www.wolverinegreen.com/sports/m-wrestl/spec-rel/utva-m-wrestl-spec-rel.html

他们没有rss提要,因此我一直在阅读使用php preg_match函数,但是语法有点混乱,我不确定该怎么做.任何建议都会得到真正的赞赏,或者如果有我没有想到的更有效的方法,那么我会开放意见.

They have no rss feed, so I have been reading into using php preg_match function but the syntax is a little confusing and I am not sure exactly how to do it. Any suggestions would be truly appreciated or if there is a more efficient method that I have not thought of then I am open to ideas.

推荐答案

// Get the page's HTML
$html = file_get_contents("http://www.wolverinegreen.com/sports/m-wrestl/spec-rel/utva-m-wrestl-spec-rel.html");

// Create a DOMDocument object and load the html into it
$dom = new DOMDocument();
$dom->loadHTML($html);

// Create an XPath object using the DOMDocument
$xpath = new DOMXPath($dom);

// Query for the a link using xpath
$items = $xpath->query("//td[1]/div/div[1]/a");

// If we find something using that query
if($items->length)
{
    // Output each item
    foreach($items as $item)
        echo $item->nodeValue . " - " . $item->getAttribute("href") . "<br />";
}

这篇关于从没有rss feed的外部站点提取最新新闻-preg_match()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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