2016-06-13 5 views
0

を取得:シンプルなHTML DOM - 私はSiterequest経由グーグルでインデックス付きのページを取得しようとしていますGoogleのインデックスページ

そこで私はget_serpsと呼ばれる機能だ:検索という

public function get_serps($pages, $start, $query) 
    { 
    //Added temporaly for Debug 
    $query = 'site:test.de'; 
    //Get Simple Html Dom 
    $parser = $this->container->get('simple_html_dom'); 

    $googleurl = 'http://www.google.de/search?num=100&start='.$start.'&hl=de&safe=off&q='.$query; 
    echo "<pre>" . $googleurl . "</pre>"; 
    $html = $parser->file_get_html($googleurl); 

    foreach ($html->find('#ires g r a') as $link) { 
     echo '</br> 2 </br>'; 
     $linkurl = $link->href; 
     echo $linkurl.'</br>'; 
     preg_match_all('#http(s)?://\b[^&]*(.*?)#', $linkurl, $target); 
     ++$count; 
    } 

    $next = $parser->modified_find('#nav tbody tr', 0); 
    $next = is_object($next) ? $next->last_child() : ''; 
    echo $next; 
    if (!empty($next) && $next->find('a')) { 
     $parser->clear(); 
     unset($parser); 
     $this->get_serps($pages, $start + 100, $query); 
    } else { 
     echo 'Count: '. $count; 
     return $count; 
    } 
} 

問題を(」 #ires gr a ')は結果を得られません。ヌルのメンバ関数modified_find()へ

コール:ちょうど空の配列

...

find関数がSimple Html Dom Package

これからのものでは私が取得していますエラーです

理由はfind関数が空の配列を返すためです。 しかし、私はなぜ機能が何も見つけることができないという考えを持っていません。

function find($selector, $idx=null, $lowercase=false) 
{ 
    echo 'Selector: ' . $selector . '</br>'; 
    $selectors = $this->parse_selector($selector); 

    if (($count=count($selectors))===0) return array(); 
    $found_keys = array(); 

    // find each selector 
    for ($c=0; $c<$count; ++$c) 
    { 
     // The change on the below line was documented on the sourceforge code tracker id 2788009 
     // used to be: if (($levle=count($selectors[0]))===0) return array(); 
     if (($levle=count($selectors[$c]))===0) return array(); 
     if (!isset($this->_[HDOM_INFO_BEGIN])) return array(); 

     $head = array($this->_[HDOM_INFO_BEGIN]=>1); 

     // handle descendant selectors, no recursive! 
     for ($l=0; $l<$levle; ++$l) 
     { 
      $ret = array(); 
      foreach ($head as $k=>$v) 
      { 
       $n = ($k===-1) ? $this->dom->root : $this->dom->nodes[$k]; 
       //PaperG - Pass this optional parameter on to the seek function. 
       $n->seek($selectors[$c][$l], $ret, $lowercase); 
      } 
      $head = $ret; 
     } 

     foreach ($head as $k=>$v) 
     { 
      if (!isset($found_keys[$k])) 
      { 
       $found_keys[$k] = 1; 
      } 
     } 
    } 

    // sort keys 
    ksort($found_keys); 

    $found = array(); 
    foreach ($found_keys as $k=>$v) 
     $found[] = $this->dom->nodes[$k]; 
     var_dump($found); 

    // return nth-element or array 
    if (is_null($idx)) return $found; 
    else if ($idx<0) $idx = count($found) + $idx; 

    return (isset($found[$idx])) ? $found[$idx] : null; 

} 

全体的な考えはSymfony Frameworkに組み込まれています!

答えて

0
Call to a member function modified_find() on null 

エラーが明確に述べ、そのfind()は問題ではありませんが、あなたがそのライム$parsernull-object

$next = $parser->modified_find('#nav tbody tr', 0); 

にそれを呼び出すという事実が定義されていません。キーは、このです:

$html = $parser->file_get_html($googleurl); 

あなたが$htmlの代わり$parserにあなたの結果を取得し、そのためのあなたその上で見つける使用する必要があります。

$next = $html->modified_find('#nav tbody tr', 0); 
+0

うん、私はした機能ので、アップロード用のコードを書き直さ呼び出しはmodified_find()でした。申し訳ありません。 新しい問題に陥っていたが、私はエラーを修正した...私は取得する必要がある検索結果を得ることができず、何の理由もない... find関数は何も見つからなかった... – Traxstar

+0

実際に使用したいhtml-syntaxは本当ですか?私はGoogle検索ブームのElemtnsの 'g'または' r'のid 'ires'でdivを見つけることができました。私はそれらの要素がHTMLに何であるかを知りません。 – DocRattie

+0

うん。 gはクラスですが、rは間違いでした。代わりにh3タグを使用してアンカーを使用しましたが、結果が見つかりません。 – Traxstar

関連する問題