2011-04-08 2 views
0

다른 화면으로 스크래핑 문제가 다시 나타납니다. 나는 화면 긁기를 위해 simple_html_dom.php를 사용하고 있습니다. 코드, 응답 텍스트 및 제 2 응답 텍스트를 붙여 넣습니다. 이 응답은 simple_html_dom이 me.it을 제공하고있는 결과로 응답은 괜찮지 만 보이지는 않습니다. 실제로 링크가있을 것입니다. 내 요청이 진행 중이고 u가 결과 (브라우저에서 표시)와 simple_html_dom이 제공하는 것을 수동으로 볼 수 있습니다.php simple_html_dom이 올바른 순서로 내용을 가져 오지 않습니다.

코드를 먼저 봅니다.

여기 SE를 SEARCH_ENGINE이다 $ 키를 키워드입니다

function search_company_name($com_id, $string, $c , $fetched)//----Function: search company name in resultant string 
{ 
    foreach($com_id AS $company => $id) 
    { 
     if(preg_match('/www\.'.$company.'/', $string)>0) 
     {   
      return array('id' => $id,'rank' => $c+1,'fetched' => $fetched+1); 
      break;    
     }   
    }  
    return NULL; 
} 


if($se === 'google.com' || $se === 'google.co.in' || $se === 'google.de' || $se === 'google.nl'|| $se === 'google.co.uk') 
{  
    $count = 0;  //---- Count the rank ----// 
    //----LOOP FOR 2 PAGES OF 100 RESULTS----// 
    for($num_of_results = 0; $num_of_results < 200; $num_of_results += 100) 
    { 
     var_dump('http://www.'.$se.'/search?q='.$key.'&start='.$num_of_results.'&num=100');// **check the link urself in ur browser** 
     $html = file_get_html('http://www.'.$se.'/search?q='.$key.'&start='.$num_of_results.'&num=10'); 

     foreach($html->find('div[id=ires] ol li') as $row) 
     {    
      $string = $row->plaintext; 
      $temp = search_company_name($company_rank, $string, $count, $counter);    
      if(!is_null($temp)) 
      { 
       reset($temp); 
       array_push($finalData, $temp); 
       foreach($company_rank as $company => $id) 
       { 
        if($temp[id] == $id) 
        { 
         unset($company_rank[$company]);break; 
        } 
       } 
       $counter++; 
      } 
      unset($temp); 
      if ($tot_company == $counter) 
      { 
       break; 
      } 
      $count++; 
     } 
     if($tot_company == $counter) 
     { 
      break; 
     } 
     $html->clear(); 
     sleep(3); 
    } 
} 

코드가 퓐이며,이 반응을 붙여 지르지 작업 (디지털 사이 니지를 말한다).

<pre class='xdebug-var-dump' dir='ltr'><small>string</small> <font color='#cc0000'>'http://www.google.co.in/search?q=Digital+Signage&amp;start=0&amp;num=10'</font> <i>(length=63)</i> 
</pre><pre class='xdebug-var-dump' dir='ltr'><small>string</small> <font color='#cc0000'>'Digital signage - Wikipedia, the free encyclopediaDigital signage is a form of electronic display that shows information, advertising and other messages. Digital signs (such as LCD, LED, plasma displays , ...Market and applications - Companies - Content - Technologyen.wikipedia.org/wiki/Digital_signage - Cached - Similar'</font> <i>(length=322)</i> 
</pre><pre class='xdebug-var-dump' dir='ltr'><small>string</small> <font color='#cc0000'>'Digital Signage | KiosksDynamic, enterprise digital signage software and hardware solutions for simple and complex digital out-of-home (DOOH) installations scaled to any sized ...www.digitalsignage.com/ - Cached - Similar'</font> <i>(length=222)</i> 

유는 두 가지 응답 (확인 urself)이 있습니다.이 결과는 1 리 및 5 리의 텍스트입니다. 그래서 2-4 Li Hav가 사라지면 Google에서 '디지털 간판 소프트웨어'에 대해 올바르게 작동합니다. Plz 도와주세요 me.my 프로젝트는 거의 끝이고 나는이 어리석은 prob에 갇혀 있어요.

두 번째 응답으로 인해 질문이 게시되지 않을 수 있습니다.

+1

검색 엔진이 컴퓨터에서 검색 한 내용과 서버에서 만든 내용을 서로 다른 결과 집합으로 반환 할 수 있습니다. 검색 결과는 지역별로 ... 인도에서 검색 한 결과가 미국에서 검색 한 결과와 다를 수 있음을 기억하십시오. –

+0

이 검색 결과를 검색하면 실제로는 1과 2가 아닌 1과 5가됩니다. 순위가 변경된 것으로 보입니다 – SimonDowdles

+0

@Salman - 그 점은 매우 유효합니다. @Aakash Google에서 검색하는 것과 동일한 컴퓨터에서 코드를 실행하고 있습니까? – SimonDowdles

답변

0

Google은 사용자 에이전트를 기반으로 구조적으로 다른 결과를 반환합니다. 사용자 에이전트 here을 찾아 동일한 스크립트를 사용하도록 스크립트를 설정하십시오.

귀하의 IP 주소에 따라 레이아웃이 다른 Google 페이지가 표시 될 수 있습니다.

관련 문제