[英]simplehtmldom get href of a title
I have a code below which is working correctly but is missing one thing. 我下面的代码可以正常工作,但是缺少一件事。 It is not returning the value for the
$item['link']
which is the href
of the title. 它不会返回
$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/>";
This is what it outputs, as you see the link key is empty. 这就是它的输出,如您所见,链接键为空。 I've tried so many things.
我已经尝试了很多东西。 Array
数组
(
[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] =>
)
You have to get the first one of the links, even though there's only one in the collection: 即使集合中只有一个,也必须获得第一个链接:
$item['link'] = $article->find('.esc-lead-article-title a', 0)->href;
Even though simple_html_dom is modeled after jQuery, it's API does not map exactly to jQuery. 即使simple_html_dom是在jQuery之后建模的,它的API也不能完全映射到jQuery。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.