0

我有一个带有提交按钮的网页,我希望 php 解析网页并单击提交按钮并获得响应(它可以是链接或另一个 html 页面。)

有没有办法使用php点击提交按钮?

我知道有类似 htmlunit for java 的东西,它允许以编程方式填写表单字段并单击提交按钮。但我想在 php.ini 中做同样的事情。

谢谢

4

4 回答 4

1

看看Selenium Web 应用程序测试系统。

于 2010-01-06T15:35:30.260 回答
0

SimpleTest PHP库还有一个页面爬虫,可以分析 HTML 页面并生成适当的 POST 请求。

于 2010-01-06T15:41:32.137 回答
0

phpWebHacks看起来很有希望完成这项任务。

功能,如网站所引用:

* Support HTTP/1.1
* Fetch web pages.
* Submit forms and upload files.
* Support https.
* Support HTTP cookies.
* Support HTTP redirects and Meta-refresh redirects.
* Support HTTP Authentication.
* Support proxy server.
* Support gzip encoding.
* Logging of HTTP streams for full debugging.
* Parsing HTML forms.
* Custom User-Agent.
于 2010-01-06T15:41:38.847 回答
0

CURL 将让您获得表单提交的结果

例如

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $urlOfFormSubmission);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, array(

        "field1"=>"data1",
        "field2"=>"data2"

    ));

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$contents = curl_exec($ch);

你也可以用 PHP Stream 函数做同样的事情

例如

$params = array('http' => array(
          'method' => "post",
          'content' => array("field1"=>"data1", "field2"=>"data2")
       ));

$ctx = stream_context_create($params);

$fp = @fopen($urlOfFormSubmission, 'rb', false, $ctx);

if (!$fp)
{
    throw new Error("Problem with ".$urlOfFormSubmission);
}

$contents = @stream_get_contents($fp);

if ($contents === false)
{
    throw new Error("Problem reading data from ".$urlOfFormSubmission);
}

无论哪种情况,$contents 都应该包含表单提交的结果

于 2010-01-06T15:53:19.777 回答