2

この URL http://www.magicbricks.com/bricks/agentSearch.htmlで DataScraping に simpleTest WebBrowser を使用しています。しかし、すべてが正しいように見えますが、常にエラーが発生しますCity Field is required。State の値が変化すると、city フィールドの値が動的に変化するという事実に問題があるのではないかと思います。解決策はありますか?これが私のコードです。

<?php
require_once('simpletest/browser.php');

$browser = &new SimpleBrowser();
$browser->addHeader('User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.2) Gecko/20100101 Firefox/6.0.2');
$browser->get('http://www.magicbricks.com/bricks/agentSearch.html');
$browser->setField('source','agentSearch');
$browser->setField('_transactionType','1');
$browser->setField('_propertyType','1');
$browser->setField('resultPerPage','50');
$browser->setField('agentSearchType','B');
$browser->setField('state','520');
$browser->setField('city','4320');
$browser->setField('keyword','');
$browser->setField('country','50');

print $browser->submitFormById('searchFormBean');
print $browser->getResponseCode()

?>
4

1 に答える 1

0

ここに私が気づいたいくつかのエラーがあります

フィールドがありません

  1. agentSearchType フィールドがありません
  2. transactionType がありません (tr​​ansactionType と _transactionType の両方があります)
  3. propertyType がありません (propertyType と _propertyType の両方があります)

次のような追加する必要があるヘッダー情報がいくつかあります。

  1. リファラー
  2. クッキー

ヘッダーを表示すると、典型的な投稿テストはこの形式になります。

        POST http://www.magicbricks.com/bricks/agentSearch.html HTTP/1.1
        Host: www.magicbricks.com
        Connection: keep-alive
        Content-Length: 173
        Cache-Control: max-age=0
        Origin: http://www.magicbricks.com
        User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.79 Safari/535.11
        Content-Type: application/x-www-form-urlencoded
        Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
        Referer: http://www.magicbricks.com/bricks/agentSearch.html
        Accept-Encoding: gzip,deflate,sdch
        Accept-Language: en-US,en;q=0.8
        Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
        Cookie: JSESSIONID=nF1UqV3DM2tZC42zByYm6Q**.MBAPP09; __utma=163479907.1423216630.1331970312.1331970312.1331970312.1; __utmb=163479907.1.10.1331970312; __utmc=163479907; __utmz=163479907.1331970312.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); _mbRunstats=3k0ilrpcgprh4tea

        source=agentSearch&agentSearchType=B&country=51&state=601&city=8417&transactionType=11951&_transactionType=1&propertyType=10001&_propertyType=1&keyword=tesy&resultPerPage=50

これが役立つことを願っています

:D

于 2012-03-17T07:56:46.857 に答える