屏幕抓取- PHP simple_html_dom没有按照正确的顺序抓取内容


screen scraping - php simple_html_dom not fetching content in proper order

我又遇到了另一个屏幕抓取问题。我使用simple_html_dom.php进行屏幕抓取。我粘贴的代码,响应文本和第二个响应文本。这些响应是simple_html_dom提供给我的结果。这看起来是对的,但事实并非如此。实际上会有一个链接,我的请求正在进行,你可以手动看到结果是什么(在你的浏览器中)和simple_html_dom给我的。

让我们先看看代码。

这里se是搜索引擎,$key是关键字(比如数字标牌)

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);
    }
}

代码是fyn,并工作到。现在粘贴两个响应。

<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>

可以看到有两个li响应(检查自己)。这些结果是第1li和5li的文本。那么2-4里到哪里去了?它是正确的工作为"数字标牌软件"在谷歌。请帮帮我。我的项目快结束了,我被这个愚蠢的问题困住了。

第二个回答可能不会引导我发布问题。

Google根据您的用户代理返回不同结构的结果。在这里找到您的用户代理,然后设置您的脚本使用相同的。

您的IP地址可以决定显示哪个Google页面,这些页面可能有不同的布局。