我要抓取内容的网站是这个http://api.94qing.com/,比如输入解梦就得到提交后的内容,请问如何可以做到啊,直接根据网站的API操作提示获取不到内容,不知道为什么???
有答案马上结贴
$url="http://api.94qing.com/?type=alexa&msg=111";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
$content = curl_exec($ch);
需要传递 cookie
给个专用函数
function QQLite_get($msg, $type='jm') { $url = 'http://api.94qing.com'; $cookiejar = realpath('cookie.txt'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_TIMEOUT, 5); curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); curl_setopt($ch, CURLOPT_REFERER, $url); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiejar); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); $r = curl_exec($ch); curl_setopt($ch, CURLOPT_URL, "$url?type=$type&msg=$msg"); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiejar); $r = curl_exec($ch); curl_close($ch); return $r;}echo QQLite_get('老虎'); //中文要 utf-8 编码的echo QQLite_get('大象');
这个我原来用过,地址好像是:http://api.qqlite.org
哇,版主大人啊,我马上试试看
http://api.94qing.com/ 这个接口有什么限制吗? 也可以说是在哪种情况下会让你用不了?
版主的方法可以实现,不过在BAE中不能用
需要传递 cookie
给个专用函数
function QQLite_get($msg, $type='jm') { $url = 'http://api.94qing.com'; $cookiejar = realpath('cookie.txt'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_TIMEOUT, 5); curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); curl_setopt($ch, CURLOPT_REFERER, $url); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiejar); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); $r = curl_exec($ch); curl_setopt($ch, CURLOPT_URL, "$url?type=$type&msg=$msg"); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiejar); $r = curl_exec($ch); curl_close($ch); return $r;}echo QQLite_get('老虎'); //中文要 utf-8 编码的echo QQLite_get('大象');
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号