我想要实现的是:
1st-我想查询像谷歌这样的页面,但没有填写它的手动搜索文件第二 - 我想得到结果并将其保存到数据库
我在这里看到了用C#做这个的例子
http://www.farooqazam.net/c-sharp-auto-click-button-and-auto-fill-form/comment-page-1/#comment-27256
但我想用PHP做,你能帮帮我吗?
谢谢
你应该使用cURL这样做,不仅因为它比file_get_contents 快,而且因为它有更多的功能.使用它的另一个原因是,正如Xeoncross在评论中正确提到的,出于安全原因,您的webhost可能会禁用file_get_contents.
一个基本的例子就是这个:
$curl_handle = curl_init();
curl_setopt( $curl_handle, CURLOPT_URL, 'http://example.com' );
curl_exec( $curl_handle ); // Execute the request
curl_close( $curl_handle );
Run Code Online (Sandbox Code Playgroud)
如果需要来自请求的返回数据,则需要指定CURLOPT_RETURNTRANSFER选项:
$curl_handle = curl_init();
curl_setopt( $curl_handle, CURLOPT_URL, 'http://example.com' );
curl_setopt( $curl_handle, CURLOPT_RETURNTRANSFER, true ); // Fetch the contents too
$html = curl_exec( $curl_handle ); // Execute the request
curl_close( $curl_handle );
Run Code Online (Sandbox Code Playgroud)
有大量的cURL选项,例如,您可以设置请求超时:
curl_setopt( $curl_handle, CURLOPT_CONNECTTIMEOUT, 2 ); // 2 second timeout
Run Code Online (Sandbox Code Playgroud)
有关所有选项的参考,请参阅curl_setopt()参考.