Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php simplehtmldom获取标题的href_Php_Arrays_Simple Html Dom - Fatal编程技术网

Php simplehtmldom获取标题的href

Php simplehtmldom获取标题的href,php,arrays,simple-html-dom,Php,Arrays,Simple Html Dom,我有一个下面的代码,它工作正常,但缺少一件事。它不会返回标题的href项['link']的值 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) {

我有一个下面的代码,它工作正常,但缺少一件事。它不会返回标题的
href
项['link']的值

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/>";

您必须获得第一个链接,即使集合中只有一个:


尽管simple_html_dom是按照jQuery建模的,但它的API并不完全映射到jQuery。

这是唯一一个使用空格的API。Mey这将起作用:
$article->find('.esc lead article title')->find('a')->href
只是猜测,
$item['link']=$article->find('.esc lead article title a',0)->href0
,没有工作过。谢谢你的努力though@acrobat-如果您查看该Google页面的源代码,您会发现class属性前没有空格,例如

(
    [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] => 
        )
$item['link'] = $article->find('.esc-lead-article-title a', 0)->href;