我要抓取内容的网站是这个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('大象');您搜索的解梦关键词:老虎