-6

からすべてのジョブをスクレイピングしようとしていGuru.com (http://www.guru.com/pro/search.aspx?#&&page=1&budget=1000-30000&cid=800&sort=PostedDateDescending)ます。このリンクを調べると、ジョブ リストをフェッチするために ajax リクエストを実行していて、ロード時にダミーの html を埋めるだけであることがわかります。これは ASP.NET サーバーであり、この ajax 要求を模倣してジョブ リストを取得しようとしています。これが私のコードです

$file_contents = parent::fetchPage($url);
        $string = tidy_repair_string($file_contents);
        $xmldoc = new DOMDocument();
        $xmldoc->loadHTML($string);
        $xpathvar = new Domxpath($xmldoc);
        
        $titleResult = $xpathvar->query('//input[@name="__VIEWSTATE"]');
        $postvars = 'ctl00%24scriptMgr=ctl00%24scriptMgr%7Cctl00%24scriptMgr&__EVENTTARGET=ctl00%24scriptMgr&__EVENTARGUMENT=page%3D1%26budget%3D1000-30000%26cid%3D800%26sort%3DPostedDateDescending&ctl00_scriptMgr_HiddenField=&__LASTFOCUS=&ctl00%24procnt%24hdnSearchId=&ctl00%24procnt%24ddlBudgetMin=0&ctl00%24procnt%24ddlBudgetMax=0&ctl00%24procnt%24Location=rbworldwide&ctl00%24procnt%24ddlCountries=Select%20One&ctl00%24procnt%24ddlCities=Select%20One&ctl00%24procnt%24txtKeyWords=Keywords%20or%20Project%20ID&ctl00%24procnt%24hdnKeyWords=&ctl00%24procnt%24ucLeadResults%24hdnSrc=&ctl00%24procnt%24ucLeadResults%24hdnPageNo=&ctl00%24procnt%24ucLeadResults%24hdnSearchResults=&ctl00%24procnt%24ucLeadResults%24hdnProjectID=&ctl00%24procnt%24txtSearchName=&ctl00%24procnt%24txtSearchName_reqd=true&ctl00%24procnt%24hdnSelectedTab=0&ctl00%24procnt%24hdnSelectSvdSearch=&ctl00%24hdnGuid=GUID&__ASYNCPOST=true&';
        $postvars .= '__VIEWSTATE='.urlencode($titleResult->item(0)->attributes->getNamedItem('value')->textContent);
        parse_str($postvars, $query);
        
        print_r($query);
        
        $ch = curl_init("http://www.guru.com/pro/search.aspx");
        curl_setopt($ch, CURLOPT_POST      ,1);
        curl_setopt($ch, CURLOPT_POSTFIELDS    ,$query);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION  ,1); 
        curl_setopt($ch, CURLOPT_HEADER      ,1);  // DO NOT RETURN HTTP HEADERS 
        curl_setopt($ch, CURLOPT_RETURNTRANSFER  ,1);  // RETURN THE CONTENTS OF THE CALL
        curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
        curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: www.guru.com',
            'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:14.0) Gecko/20100101 Firefox/14.0.1',
            'Accept: text/plain, text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
            'Accept-Language: en-us,en;q=0.5',
            'Accept-Encoding: gzip, deflate',
            'Connection: keep-alive',
            'X-MicrosoftAjax: Delta=true',
            'Cache-Control: no-cache, no-cache',
            'Content-Type: application/x-www-form-urlencoded; charset=utf-8',
            'Referer: http://www.guru.com/pro/search.aspx?',
            'Content-Length: 15818',
            'Pragma: no-cache'
        ));
        echo $Rec_Data = curl_exec($ch);
        $Rec_Data = gzinflate(substr($Rec_Data, 10, -8));
        echo $Rec_Data;

ajax リクエスト用に送信されるライブ HTTP ヘッダー Firefox プラグインで表示されるのと同じヘッダーを送信しています。次の応答ヘッダーを受信して​​います。

HTTP/1.1 100 Continue

HTTP/1.1 200 OK
Cache-Control: private
Content-Type: text/html; charset=utf-8
Content-Encoding: gzip
Vary: Accept-Encoding
Server: Microsoft-IIS/7.0
Set-Cookie: ASP.NET_SessionId=eip5l545vkyk3aqhq5kliijj; path=/; HttpOnly
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Date: Tue, 21 Aug 2012 21:28:57 GMT
Content-Length: 44051

一方、ライブ HTTP ヘッダー プラグインで表示される応答ヘッダーは、guru.com によって ajax が行われたときに受信されます。

HTTP/1.1 200 OK
Cache-Control: private
Content-Type: text/plain; charset=utf-8
Content-Encoding: gzip
Vary: Accept-Encoding
Server: Microsoft-IIS/7.0
Set-Cookie: ASP.NET_SessionId=bnlurvq3crot1r55juykpt3y; path=/; HttpOnly
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Date: Tue, 21 Aug 2012 19:25:19 GMT
Content-Length: 43290

Guru.com はジョブ リストを受信して​​いますが、私はジョブを含まないダミー HTML を受信して​​います。私のコードで何が間違っているのか誰か教えてください。以下は、Ajax 呼び出しのために Guru.com からサーバーに送信される要求ヘッダーです。

POST /pro/search.aspx HTTP/1.1
Host: www.guru.com
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:14.0) Gecko/20100101 Firefox/14.0.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
X-MicrosoftAjax: Delta=true
Cache-Control: no-cache, no-cache
Content-Type: application/x-www-form-urlencoded; charset=utf-8
Referer: http://www.guru.com/pro/search.aspx?
Content-Length: 15818
Pragma: no-cache
ctl00%24scriptMgr=ctl00%24scriptMgr%7Cctl00%24scriptMgr&__EVENTTARGET=ctl00%24scriptMgr&__EVENTARGUMENT=page%3D1%26budget%3D1000-30000%26cid%3D800%26sort%3DPostedDateDescending&ctl00_scriptMgr_HiddenField=&__LASTFOCUS=&__VIEWSTATE=%2FwEPDwULLTE0NDg0NjI5MzIPZBYCZg9kFgQCBQ8PFgIeB1Zpc2libGVoZGQCBw9kFgICBw9kFhICBA9kFgJmD2QWAgIBD2QWAgIBDzwrAAkAZAIHDxYCHg5Qb3N0QmFja1NjcmlwdAUsX19kb1Bvc3RCYWNrKCdjdGwwMCRwcm9jbnQkbGlua0NuZnJtRGVsJywnJylkAgsPZBYCZg9kFgICAw88KwAJAGQCDA9kFgJmD2QWBAIBDxBkZBYBZmQCAw8QZGQWAWZkAg0PZBYCZg9kF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jbnQkcmJ3b3JsZHdpZGUFFmN0bDAwJHByb2NudCRyYkNvdW50cnkFFmN0bDAwJHByb2NudCRyYkNvdW50cnkFE2N0bDAwJHByb2NudCRyYkNpdHkFE2N0bDAwJHByb2NudCRyYkNpdHn8aeALBWdIWf7e1179CNtoWvy2eg%3D%3D&ctl00%24procnt%24hdnSearchId=&ctl00%24procnt%24ddlBudgetMin=0&ctl00%24procnt%24ddlBudgetMax=0&ctl00%24procnt%24Location=rbworldwide&ctl00%24procnt%24ddlCountries=Select%20One&ctl00%24procnt%24ddlCities=Select%20One&ctl00%24procnt%24txtKeyWords=Keywords%20or%20Project%20ID&ctl00%24procnt%24hdnKeyWords=&ctl00%24procnt%24ucLeadResults%24hdnSrc=&ctl00%24procnt%24ucLeadResults%24hdnPageNo=&ctl00%24procnt%24ucLeadResults%24hdnSearchResults=&ctl00%24procnt%24ucLeadResults%24hdnProjectID=&ctl00%24procnt%24txtSearchName=&ctl00%24procnt%24txtSearchName_reqd=true&ctl00%24procnt%24hdnSelectedTab=0&ctl00%24procnt%24hdnSelectSvdSearch=&ctl00%24hdnGuid=GUID&__ASYNCPOST=true&

これは、私が受け取った応答のスクリーンショットです。

ここに画像の説明を入力

4

2 に答える 2

1

アップデート

彼らは、ページをレンダリングするために必要な機能として、またはボットから保護するために JavaScript を使用しているようです。提供する HTTP クライアントは、JavaScript も解釈できる必要があります。

元の返信

リクエストごとに異なる ASP.Net セッション Cookie を送信しています。

おそらく、Guru.com はデータを返す前に有効な認証済みセッションをチェックします。

最初にプログラムで Web サイトにログインし、有効なセッション ID を取得してから、その後の Ajax リクエストでその ID を使用する必要があります。

于 2012-08-21T21:48:17.280 に答える
-2

問題のサイトは、POST 変数の位置を追跡していました。firebug (または Live Http Headers) に従って再配置し、バンバン データを表示します。私の最終的なコードは( $postvars 変数をチェックしてください)

$file_contents = parent::fetchPage($url);
        $string = tidy_repair_string($file_contents);
        $xmldoc = new DOMDocument();
        $xmldoc->loadHTML($string);
        $xpathvar = new Domxpath($xmldoc);

        $titleResult = $xpathvar->query('//input[@name="__VIEWSTATE"]');
        $postvars = 'ctl00%24scriptMgr=ctl00%24scriptMgr%7Cctl00%24scriptMgr&__EVENTTARGET=ctl00%24scriptMgr&__EVENTARGUMENT=page%3D1%26budget%3D1000-30000%26cid%3D800%26sort%3DPostedDateDescending&ctl00_scriptMgr_HiddenField=&__LASTFOCUS=&'.'__VIEWSTATE='.urlencode($titleResult->item(0)->attributes->getNamedItem('value')->textContent)."&".'ctl00%24procnt%24hdnSearchId=&ctl00%24procnt%24ddlBudgetMin=0&ctl00%24procnt%24ddlBudgetMax=0&ctl00%24procnt%24Location=rbworldwide&ctl00%24procnt%24ddlCountries=Select%20One&ctl00%24procnt%24ddlCities=Select%20One&ctl00%24procnt%24txtKeyWords=Keywords%20or%20Project%20ID&ctl00%24procnt%24hdnKeyWords=&ctl00%24procnt%24ucLeadResults%24hdnSrc=&ctl00%24procnt%24ucLeadResults%24hdnPageNo=&ctl00%24procnt%24ucLeadResults%24hdnSearchResults=&ctl00%24procnt%24ucLeadResults%24hdnProjectID=&ctl00%24procnt%24txtSearchName=&ctl00%24procnt%24txtSearchName_reqd=true&ctl00%24procnt%24hdnSelectedTab=0&ctl00%24procnt%24hdnSelectSvdSearch=&ctl00%24hdnGuid=GUID&__ASYNCPOST=true&';
        parse_str($postvars, $query);

        print_r($query);

        $ch = curl_init("http://www.guru.com/pro/search.aspx");
        curl_setopt($ch, CURLOPT_POST      ,1);
        curl_setopt($ch, CURLOPT_POSTFIELDS    ,$postvars);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION  ,1); 
        curl_setopt($ch, CURLOPT_HEADER      ,0);  // DO NOT RETURN HTTP HEADERS 
        curl_setopt($ch, CURLOPT_RETURNTRANSFER  ,1);  // RETURN THE CONTENTS OF THE CALL
        curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
        curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
        curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');         
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: www.guru.com',
            'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:14.0) Gecko/20100101 Firefox/14.0.1',
            'Accept: text/plain, text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
            'Accept-Language: en-us,en;q=0.5',
            'Accept-Encoding: gzip, deflate',
            'Connection: keep-alive',
            'X-MicrosoftAjax: Delta=true',
            'Cache-Control: no-cache, no-cache',
            'Content-Type: application/x-www-form-urlencoded; charset=utf-8',
            'Referer: http://www.guru.com/pro/search.aspx?',
            'Content-Length: 15818',
        ));
        echo $Rec_Data = curl_exec($ch);
        $Rec_Data = gzinflate(substr($Rec_Data, 10, -8));
于 2012-08-21T22:32:12.943 に答える