我有一个下面的代码可以正常工作但缺少一件事。它没有返回$item['link']
哪个是href
标题的值。
include('simple_html_dom.php');
$html = file_get_html('http://news.google.com/news/section?pz=1&cf=all&ned=us&q=newzealand');
foreach($html->find('.blended-wrapper') as $article) {
$item['title'] = $article->find('span.titletext', 0)->plaintext;
$item['source'] = $article->find('span.esc-lead-article-source', 0)->plaintext;
$item['clip'] = $article->find('div.esc-lead-snippet-wrapper', 0)->plaintext;
$item['link'] = $article->find('.esc-lead-article-title a')->href;
$articles[] = $item;
}
echo "<pre>";
print_r($articles);
echo "<pre/>";
这就是它输出的内容,因为您看到链接键是空的。我已经尝试了很多东西。大批
(
[0] => Array
(
[title] => New Zealand dominate 2011 after 24 years of pain
[source] => Times of India
[clip] => WELLINGTON: After 24 years of stumbles, disappointments and plain old chokes, New Zealand finally lived up to their billing as world rugby's premier side in 2011.
[link] =>
)
[1] => Array
(
[title] => PRESS DIGEST-New Zealand newspapers - Dec 29
[source] => Reuters
[clip] => WELLINGTON Dec 29 (Reuters) - Following are some of the lead stories from New Zealand metropolitan newspapers on Thursday. Stories may be taken from either the paper or Internet editions of the papers.
[link] =>
)