Home >php教程 >php手册 >php使用curl模拟登录后采集页面的例子

php使用curl模拟登录后采集页面的例子

WBOY
WBOYOriginal
2016-06-07 11:35:151313browse

php使用curl模拟登录后采集页面的例子
$curl = curl_init();<br> $cookie_jar = tempnam('./tmp','cookie');<br> curl_setopt($curl, CURLOPT_URL,'http://b2b.bookuu.com/b2b_club/checkUser.jsp');//这里写上处理登录的界面<br> curl_setopt($curl, CURLOPT_POST, 1);<br> $request = 'user=xxx&password=xxx';<br> curl_setopt($curl, CURLOPT_POSTFIELDS, $request);//传 递数据<br> curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie_jar);// 把返回来的cookie信息保存在$cookie_jar文件中<br> curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);//设定返回 的数据是否自动显示<br> curl_setopt($curl, CURLOPT_HEADER, false);//设定是否显示头信 息<br> curl_setopt($curl, CURLOPT_NOBODY, false);//设定是否输出页面 内容<br> curl_exec($curl);//返回结果<br> curl_close($curl); //关闭<br>  <br> $curl2 = curl_init();<br> curl_setopt($curl2, CURLOPT_URL, 'http://b2b.bookuu.com/search/b2b_zxsm_new.jsp');//登陆后要从哪个页面获取信息<br> curl_setopt($curl2, CURLOPT_HEADER, false);<br> curl_setopt($curl2, CURLOPT_RETURNTRANSFER, 1);<br> curl_setopt($curl2, CURLOPT_COOKIEFILE, $cookie_jar);<br> $content = curl_exec($curl2);

AD:真正免费,域名+虚机+企业邮箱=0元

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn