Php 如何从cURL返回的html中获取值输入?
我只需要捕获从curl_exec()函数返回的html输入值。此函数返回页面的完整html,是否有任何方法仅获取输入值 我的代码:Php 如何从cURL返回的html中获取值输入?,php,html,curl,Php,Html,Curl,我只需要捕获从curl_exec()函数返回的html输入值。此函数返回页面的完整html,是否有任何方法仅获取输入值 我的代码: public function searchUser(Request $request){ $data = $request->all(); $cURL = curl_init('http://www.example.com/result.php'); curl_setopt($cURL, CURLOPT_HEADER,
public function searchUser(Request $request){
$data = $request->all();
$cURL = curl_init('http://www.example.com/result.php');
curl_setopt($cURL, CURLOPT_HEADER, false);
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true);
$dados = array(
'num_cnpj' => $data['cnpj'],
'botao' => 'Consultar'
);
curl_setopt($cURL, CURLOPT_POST, true);
curl_setopt($cURL, CURLOPT_POSTFIELDS, $dados);
curl_setopt($cURL, CURLOPT_REFERER, 'http://www.example.com/index.php');
$result = curl_exec($cURL);
curl_close($cURL);
return $result;
}
您可以尝试使用许多PHP dom解析器中的一个
没有任何功能可以帮助您完成此类操作。您需要编写一个解析器来获取这些值,或者您可以实现一个rest api来获取数据。谢谢您的回答,但是$dom->getElementsByTagName('input')方法没有捕获输入,返回的是空的。哦,很抱歉,我的html没有返回输入,而是一个包含结果的表,更改了td的输入标记,现在正在工作。非常感谢。
<?php
# Create a DOM parser object
$dom = new DOMDocument();
# Parse the HTML
# The @ before the method call suppresses any warnings that
# loadHTML might throw because of invalid HTML in the page.
@$dom->loadHTML($result);
# Iterate over all the <input> tags
foreach($dom->getElementsByTagName('input') as $input) {
# Show the attribute value
echo $input->getAttribute('value');
echo "<br />";
}
?>