簡體   English   中英

單擊使用PHP提交按鈕

[英]clicking on submit button using php

我有一個帶有“提交”按鈕的網頁,我希望php解析該網頁並單擊“提交”按鈕並獲得響應(它可以是鏈接或另一個html頁面。)

有什么辦法可以使用php單擊提交按鈕嗎?

我知道有一種類似htmlunit for java的東西,它允許人們以語法方式填寫表單字段,然后單擊提交按鈕。 但是我想在php中做同樣的事情。

謝謝

看一下Selenium Web應用程序測試系統。

SimpleTest PHP庫還具有一個頁面搜尋器,它可以分析HTML頁面並生成適當的POST請求。

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.

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都應包含表單提交的結果

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM