内容未正确发布?

发布于 2024-12-11 03:19:42 字数 1073 浏览 1 评论 0原文

我正在使用 simpleTest WebBrowser 在此 URL http://www.magicbricks.com/bricks/agentSearch 上进行数据抓取.html。但是,尽管一切看起来都正确,但我总是收到错误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()

?>

I am using simpleTest WebBrowser for DataScraping on this URL http://www.magicbricks.com/bricks/agentSearch.html. But though everything seems right I always get the error City Field is required. I guess the problem might be with the fact that values in city field changes dynamically when value of State changes. Any solutions? Here is my code.

<?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()

?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑叹一世浮沉 2024-12-18 03:19:42

以下是我注意到的一些错误 字段

丢失

  1. 缺少agentSearchType字段
  2. 缺少transactionType(有transactionType和_transactionType)
  3. 缺少propertyType(有propertyType和_propertyType)

您需要添加一些标头信息,例如

  1. Referer
  2. Cookie

典型的后期测试如果您查看标题,应该采用这种格式

        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

Here are some errors i noticed

Field Missing

  1. Missing agentSearchType field
  2. Missing transactionType ( There is Both transactionType & _transactionType)
  3. missing propertyType ( There is both propertyType & _propertyType)

There are some header information you need to add such as

  1. Referer
  2. Cookie

A typical post test should come this format if you view the headers

        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

I hope this helps

:D

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文