PHP를 사용하여 제출 버튼을 클릭합니다
-
19-09-2019 - |
문제
제출 버튼이있는 웹 페이지가 있는데 PHP가 웹 페이지를 구문 분석하고 제출 버튼을 클릭하고 응답을 받기를 원합니다 (링크 또는 다른 HTML 페이지가 될 수 있습니다.)
PHP를 사용하여 제출 버튼을 클릭하는 방법이 있습니까?
Java 용 htmlunit과 같은 것이 있다는 것을 알고 있습니다. 하지만 PHP에서도 똑같이하고 싶습니다.
감사
해결책
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 스트림 기능으로 동일한 작업을 수행 할 수도 있습니다.
예를 들어
$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);
}
두 경우 모두 $ 컨텐츠는 양식 제출 결과를 포함해야합니다.
다른 팁
보세요 셀렌 웹 응용 프로그램 테스트 시스템.
그만큼 단순합니다 PHP 라이브러리에는 HTML 페이지를 분석하고 적절한 게시물 요청을 생성 할 수있는 페이지 크롤러가 있습니다.
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.
제휴하지 않습니다 StackOverflow