请教一个用php能得到google查询数据吗 大致是输入检索条件,点查询按钮,然后查询一下google,然后把查出的数据信息插到数据库中。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这个在CSDN上记得有人问过的,这个不知道是哪位的回答了,借用下:服务器端: <%response.contenttype = "text/xml "%> <%response.charset = "GB2312 "%> <!--#include file= "../include/function.asp "--> <% 'on error resume next Function send_request(s) Set Retrieval = CreateObject( "Microsoft.XMLHTTP ") dim url url = "http://www.google.cn/search?q= " & s & _ "&ie=gb2312&hl=zh-CN&lr=lang_zh-cn&oe=utf-8&sa=N " With Retrieval .Open "Get ", url, False, " ", " " .setRequestHeader "Content-Length ", len(url) .setRequestHeader "Content-Type ", "application/x-www-form-urlencoded " .Send if err.number <> 0 then send_request = err.description else send_request = replace(.responsetext, " " " ", "" ") end if End With Set Retrieval = Nothing End Function dim keyword keyword=Request( "q ") response.write " <?xml version= " "1.0 " " encoding= " "GB2312 " "?> " & chr(13) response.write " <root> " & chr(13) response.write " <query> <![CDATA[ " & send_request(keyword) & "]]> </query> " & chr(13)response.write " </root> " %> 以上存为QueryWeb.asp 客户端 listBody2.innerHTML = " <img src=\ "images/loading.gif\ "> 数据正在查询,请稍候... "; var keyword = keywords.innerText.split( " "); var q = " "; for(i=0; i <keyword.length; i++){ q += i != keyword.length -1 ? keyword[i]+ "+ " : keyword[i]; } url = "app/QueryWeb.asp?q= "+q; XMLHttp.sendReq( "GET ", url, ' ', doWriteList22); function doWriteList22(http){ if(http.readyState == 4){ var xml = http.responseXML; var res = xml.selectSingleNode( "root/query ").childNodes[0].nodeValue; res = res.replace(/\ "/ig, ' '); var resArr = res.match(/ <h2 class=r> ((?! <\/h2> ).)* <\/h2> /ig); var HTML = " <table width=100% cellpadding=5 cellspacing=0 border=0> "; var href = " ", link = " ", link2 = " "; for(i=0;i <10;i++){ if(i == resArr.length) break; href = resArr[i].match(/href=(.[^ ]*) /ig); link = resArr[i].match(/ <a.*\/a> /ig); link2 = link[0].replace(/ <(.[^> ]*)> /ig, " "); HTML += " <tr> <td width=80% valign=center height=20px> <img src=images/listHeader.gif> "+ " <a "+href[0].replace(/"/ig, " ")+ " target=_blank title=\ " "+link2+ "\ " class=tabList> "+link2.truncate(25)+ " </a> </td> </tr> "; } HTML += " </table> " listBody2.innerHTML = HTML; } } 用以上方式实现的页面,页面中点击左侧站外链接后就是通过GOOGLE搜索“关键字”后取得的内容 http://www.speedsoftech.com/readnews.htm?newsid=49 你可以用google的开放api,或者用zend framework,它直接封闭了google的api google api 看下官方文档 <?phpheader("Content-Type: text/html;charset=utf-8");$content="中国人民银行";$url = "http://www.google.com.hk/search?hl=zh-CN&source=hp&q={$content}&btnG=Google+%E6%90%9C%E7%B4%A2&meta=lr%3Dlang_zh-CN&aq=f&aqi=&aql=&oq=&gs_rfai=";$cookie_file = "google.txt";$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);$contents = curl_exec($ch);curl_close($ch);echo $contents ;?>[/code] 如何分割数组? 怎么改这个语句 显示 又花了半天时间写了个php上传类 如何取出readdir中的值 phpMyAdmin新添加的用户无法登录 LINUX 服务器下 php 找不到 php_mbstring.dll php_mcrypt.dll 比较难的页面读取问题? 分页显示 这个字符怎么输出 高分求救!!! ftp上传网站程序没有权限 怎么解决这个问题“您看到这个错误页面是因为应用程序抛出了没有捕获的异常。”
服务器端:
<%response.contenttype = "text/xml "%>
<%response.charset = "GB2312 "%>
<!--#include file= "../include/function.asp "-->
<%
'on error resume next
Function send_request(s)
Set Retrieval = CreateObject( "Microsoft.XMLHTTP ")
dim url
url = "http://www.google.cn/search?q= " & s & _
"&ie=gb2312&hl=zh-CN&lr=lang_zh-cn&oe=utf-8&sa=N "
With Retrieval
.Open "Get ", url, False, " ", " "
.setRequestHeader "Content-Length ", len(url)
.setRequestHeader "Content-Type ", "application/x-www-form-urlencoded "
.Send
if err.number <> 0 then
send_request = err.description
else
send_request = replace(.responsetext, " " " ", "" ")
end if
End With
Set Retrieval = Nothing
End Function dim keyword
keyword=Request( "q ")
response.write " <?xml version= " "1.0 " " encoding= " "GB2312 " "?> " & chr(13)
response.write " <root> " & chr(13)
response.write " <query> <![CDATA[ " & send_request(keyword) & "]]> </query> " & chr(13)
response.write " </root> "
%>
以上存为QueryWeb.asp 客户端
listBody2.innerHTML = " <img src=\ "images/loading.gif\ "> 数据正在查询,请稍候... ";
var keyword = keywords.innerText.split( " ");
var q = " ";
for(i=0; i <keyword.length; i++){
q += i != keyword.length -1 ? keyword[i]+ "+ " : keyword[i];
}
url = "app/QueryWeb.asp?q= "+q;
XMLHttp.sendReq( "GET ", url, ' ', doWriteList22); function doWriteList22(http){
if(http.readyState == 4){
var xml = http.responseXML;
var res = xml.selectSingleNode( "root/query ").childNodes[0].nodeValue;
res = res.replace(/\ "/ig, ' ');
var resArr = res.match(/ <h2 class=r> ((?! <\/h2> ).)* <\/h2> /ig);
var HTML = " <table width=100% cellpadding=5 cellspacing=0 border=0> ";
var href = " ", link = " ", link2 = " ";
for(i=0;i <10;i++){
if(i == resArr.length) break;
href = resArr[i].match(/href=(.[^ ]*) /ig);
link = resArr[i].match(/ <a.*\/a> /ig);
link2 = link[0].replace(/ <(.[^> ]*)> /ig, " ");
HTML += " <tr> <td width=80% valign=center height=20px> <img src=images/listHeader.gif> "+
" <a "+href[0].replace(/"/ig, " ")+ " target=_blank title=\ " "+link2+ "\ " class=tabList> "+link2.truncate(25)+ " </a> </td> </tr> ";
}
HTML += " </table> "
listBody2.innerHTML = HTML;
}
} 用以上方式实现的页面,页面中点击左侧站外链接后就是通过GOOGLE搜索“关键字”后取得的内容
http://www.speedsoftech.com/readnews.htm?newsid=49
header("Content-Type: text/html;charset=utf-8");
$content="中国人民银行";
$url = "http://www.google.com.hk/search?hl=zh-CN&source=hp&q={$content}&btnG=Google+%E6%90%9C%E7%B4%A2&meta=lr%3Dlang_zh-CN&aq=f&aqi=&aql=&oq=&gs_rfai=";$cookie_file = "google.txt";$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
$contents = curl_exec($ch);
curl_close($ch);
echo $contents ;
?>[/code]