WordPress插件,用于抓取BBCs最受欢迎的部分
我正试图从bbc.co.uk/news/网站上把最受欢迎的部分刮到WordPress插件中。我目前有以下代码:WordPress插件,用于抓取BBCs最受欢迎的部分,wordpress,simple-html-dom,domparser,Wordpress,Simple Html Dom,Domparser,我正试图从bbc.co.uk/news/网站上把最受欢迎的部分刮到WordPress插件中。我目前有以下代码: <?php /* Plugin Name: BBC Scrape Description: Reprints the BBCs Most popular stories Author: The Health Check Team Version: 0.1-alpha */ include('simple_html_dom.php');
<?php
/*
Plugin Name: BBC Scrape
Description: Reprints the BBCs Most popular stories
Author: The Health Check Team
Version: 0.1-alpha
*/
include('simple_html_dom.php');
$articles = array();
getArticles('http://www.bbc.co.uk/news/');
function getArticles($page) {
global $articles;
<br>
$html = new simple_html_dom();
$html->load_file($page);
$items = $html->find('div[class=livestats livestats-tabbed tabbed most-popular]');
foreach($items as $post) {
# remember comments count as nodes
$articles[] = array($post->children(3)->outertext,
$post->children(4)->first_child()->outertext,
$post->children(5)->first_child()->outertext);
}
}
?>
我以前使用过像wp\u remote\u get
这样的功能,但是这只是获得了整个站点。我无法使用DOM解析将其过滤到最流行的部分。
我在这段代码中遇到的错误是未编辑的simple\u html\u dom.php
文档中的函数find()
错误
我基本上不明白我怎么能自己获得bbc.co.uk/news栏目中最受欢迎的栏目 我猜BBC不会喜欢你们试图归档的东西。我明白,这只是我试图做的一种学习技巧。因为它将帮助我如何使用DOM解析和simple_html_DOM.php文件。我不是为了我的利益而使用它。