【问题标题】:Display news from other web page显示来自其他网页的新闻
【发布时间】:2011-02-01 23:15:42
【问题描述】:

我想在我的网页上显示来自另一个网页的新闻,但我想不出最好的方法。

另一个网页上的新闻显示在一个 div 类中,如下所示

<div class="news-container"> 
<div class="news-list"><a href="news/1/" title="abcd"><img src="abcd.jpg" /><strong>abcd</strong></a> 
    <p>What you see is what you get. <span class="morelink"><a href="news/1/" title="abcd">Read more</a></span></p> 
    <div class="clear-both"></div> 
</div> 
<div class="news-list"><a href="news/2/" title="efgh"><img src="efgh.jpg" /><strong>efgh</strong></a> 
    <p>What you see is what you get. <span class="morelink"><a href="news/3/" title="abcd">Read more</a></span></p> 
    <div class="clear-both"></div> 
</div> 
<div class="news-list"><a href="news/3/" title="ijkl"><img src="ijkl.jpg" /><strong>ijkl</strong></a> 
    <p>What you see is what you get. <span class="morelink"><a href="news/3/" title="abcd">Read more</a></span></p> 
    <div class="clear-both"></div> 
</div> 
<div class="news-list"><a href="news/4/" title="mnop"><img src="mnop.jpg" /><strong>mnop</strong></a> 
    <p>What you see is what you get. <span class="morelink"><a href="news/4/" title="abcd">Read more</a></span></p> 
    <div class="clear-both"></div> 
</div>

我希望能够循环浏览新闻并将它们显示在我自己的页面上,并根据我们自己的网站布局重新排列。

<div class="other-news"> 
<div class="news-list"><strong>abcd</strong>
    <p>What you see is what you get. <a href="news/1/" title="abcd"><img src="abcd.jpg" /></a></p> 
</div> 
<div class="news-list"><strong>efgh</strong>
    <p>What you see is what you get. <a href="news/3/" title="abcd"><img src="efgh.jpg" /></a> </p> 
</div> 
<div class="news-list"><strong>ijkl</strong>
    <p>What you see is what you get. <a href="news/3/" title="abcd"><img src="ijkl.jpg" /></a> </p> 
</div> 
<div class="news-list"><strong>mnop</strong>
    <p>What you see is what you get. <a href="news/4/" title="abcd"><img src="mnop.jpg" /></a> </p>
</div>

欢迎所有建议。

// 尼堡

【问题讨论】:

    标签: php cross-domain


    【解决方案1】:

    您需要查看 PHP cURL 或 file_get_contents(安全问题)或查看 PHP HTML DOM Parser。

    还要看看你做什么的合法性? (如果他们想让你有内容,他们通常会提供一个 API)

    【讨论】:

    • 合法性已经过检查。总公司没有人力来完成这项任务(!)。我看过 PHP cURL 和 DOM 解析器,但我不确定哪一个可以以最简单的方式完成这项工作。欢迎提出建议。
    • 那没问题。只需使用上述方法之一,我推荐 HTLM DOM Parser - simplehtmldom.sourceforge.net
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-05
    • 2012-05-28
    • 2020-11-03
    • 2015-08-17
    • 2011-01-10
    • 1970-01-01
    相关资源
    最近更新 更多