2016-02-12 50 views
0

我只需要捕获从curl_exec()函数返回的html输入的值。这个函数返回页面的完整html,是否有任何方法只取得输入的值?如何获得从cURL返回的html值输入?

我的代码:

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; 

} 
+0

没有的功能,它可以帮助你这个样子。你需要编写一个解析器来获取这些值,或者你可以实现一个休息API来获取数据。 – Afnan

回答

0

你可以尝试使用许多PHP DOM解析器之一。

http://php.net/manual/en/domdocument.loadhtml.php

<?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 />"; 
} 
?> 
+0

谢谢你的回答,但方法$ dom-> getElementsByTagName('input')不捕获输入,返回空。 – let

+0

哦,对不起,我的html没有返回输入,而是一个包含结果的表格,改变了td的输入标签,现在正在工作。谢谢! – let