通过本文主要向大家介绍了百度云搜索引擎入口,百度搜索引擎,百度云网盘搜索引擎,百度网盘搜索引擎入口,百度云搜索引擎等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
想拥有属于自己的搜索引擎吗?采用目前流行的数据采集方法,你就可以立即拥有。下面就教你一步步地去实现。
一、认识百度搜索
百度搜索,全球最大中文搜索引擎,2005年8月5日在美国纳斯达克上市交易,目前是国内用户使用率最高的搜索引擎,提供网页、新闻、图片、音乐、地图等各种搜索
1、百度网页搜索的查询参数
必备参数
☆ wd--查询的关键词(Keyword)
☆ pn--显示结果的页数(Page Number)
☆ cl--搜索类型(Class),cl=3为网页搜索
可选参数
☆ rn--搜索结果显示条数(Record Number),取值范围在10--100条之间,缺省设置rn=10
☆ ie--查询输入文字的编码(Input Encoding),缺省设置ie=gb2312,即为简体中文
☆ tn--提交搜索请求的来源站点
几个有用的tn
tn=baidulocal 表示百度站内搜索,返回的结果很干净,无广告干扰。比如,在百度站内搜索"快乐",看看返回结果是不是很清爽。
tn=baiducnnic 想把百度放在框架中吗?试试这个参数就可以了,是百度为Cnnic定制的
☆ si--在限定的域名中搜索,比如想在新浪的站内搜索可使用参数si=sina.com.cn,要使这个参数有效必须结合ct参数一起使用。
☆ ct--此参数的值一般是一串数字,估计应该是搜索请求的验证码
si和ct参数结合使用,比如在sina.com.cn中搜索"理想",可用:http://www.baidu.com/baidu?ie=utf-8&am ... n&cl=3&word=理想
☆ bs--上一次搜索的关键词(Before Search),估计与相关搜索有关
2、百度搜索结果页面结构
按源代码结构自上而下为:
搜索框
右侧的火爆地带固定排名
搜索结果
分页区
相关搜索
底部搜索框
版权区
其中"搜索结果、分页区"这两部分就是我们需要的有效数据,根据其代码结果可以发现其唯一的字符串标识,通过这个标识截取内容就可以了,具体看后面的代码。
二、核心函数--使用asp的xmlhttp组件
数据采集程序,俗称小偷程序,其核心部分就是这个xmlhttp组件,用xmlhttp采集数据有些老生常谈了,网上资料也不少,一般的采集代码都是
set http=Server.createobject("MSXML2.XMLHTTP")
Http.open "GET",url,false '打开xmlhttp
Http.send() '发送请求
if Http.readystate<>4 then
exit function
end if
getHTTPPage=bytesToBSTR(Http.responseBody,"GB2312") '返回结果(一般是字节流),并将字节流转换为字符串
set http=nothing '释放xmlhttp
详细应用见下面的完整代码
三、完整代码(文件名:searchi_bd.asp)
<%
option explicit
Dim wd,pn
wd = Request("wd")
pn = Request.QueryString("pn")
'开始错误处理
On Error Resume Next
If Err.Number <> 0 Then
Response.Clear
'显示错误信息给用户
Response.Write "<p align='center' ><font size=3> 出错了,请重新打开百度搜索.</font></p>"
end if
%>
<HTML>
<HEAD>
<TITLE>百度搜索--<%=wd%></TITLE>
</HEAD>
<STYLE type=text/css>
<!--
body,td{font-family:arial}
TD{FONT-SIZE:9pt;LINE-HEIGHT:18px}
.cred{color:#FF0000}
//-->
</STYLE>
<BODY leftmargin="0" topmargin="3" marginwidth="0" marginheight="0">
<table align="center" width="98%" cellspacing="0" cellpadding="0" border="0" bgcolor="#ffffff" >
<tr>
<form name="f1" method="post" action="searchi_bd.asp">
<td width=150 height=50>
你的LOGO
</td>
<td align="left">
<input name=wd size="40" maxlength="100" title="输入关键字,然后Let's Searching..." value="<%=wd%>">
<input type="submit" value=" 百度搜索 ">
</td></form></tr>
</table>
<%
Dim strUrl,strTmp_bd,strInfo,strPage,strPageSum_bd,strQtime_bd
Dim bNoResult_bd,regEx,patrn
'百度查询字符串
strUrl = "http://www.baidu.com/s?ie=gb2312&wd="&wd&am ... &pn&"&cl=3"
'开始采集
strTmp_bd = GetHTTPPage(strUrl)
If InStr(strtmp_bd,"未找到和您的查询")<>0 Then
bNoResult_bd=1
End If
'截取"搜索结果"部分的内容
strinfo = strCut(strTmp_bd,"<DIV id=ScriptDiv></DIV>","<br clear=all>",2)
patrn="</td></tr></table><br>"
Set regEx = New RegExp ' 建立正则表达式。
regEx.Pattern = patrn ' 设置模式。
regEx.IgnoreCase = true
regEx.Global = false
strinfo=regEx.replace(strinfo,"")
'截取"分页区"部分的内容
strPage = strCut(strTmp_bd,"<br clear=all>","<br>",2)
strPage = Replace(strPage,"href=s?","href=searchi_bd.asp?")
'结果数量与用时
strPageSum_bd=strCut(strtmp_bd,"找到相关网页约","篇",2)
if not IsNumeric(strPageSum_bd) then
strPageSum_bd=strCut(strtmp_bd,"找到相关网页","篇",2)
end if
strQtime_bd=strCut(strtmp_bd,"用时","秒",2)
Set strTmp_bd=nothing
%>
<!-- T1-Start -->
<table cellspacing=0 cellpadding=0 border=0 width=98% align="center">
<tr valign=center align=middle height=18>
<td width=1 bgcolor=#999999>
<td nowrap style="FONT-WEIGHT:bold;COLOR:#ffffff;BACKGROUND-COLOR:#0033cc" width=64>互联网</td>
<td align=right bgcolor=#eeeeee><nobr>找到符合<b><%=wd%></b>的相关网页<b><%=strPageSum_bd%></b>篇,用时<b><%=strQtime_bd%></b>秒</nobr> </td>
</tr>
<tr><td bgcolor=#999999 colspan=3 height=2></td></tr></table>
</td>
</tr>
</table>
<%
if wd="" then
Response.Write "<p align='center' ><font size=-1> 您好,请在搜索框中输入关键词.</font></p>"
elseif bNoResult_bd=1 then
Response.Write "<p align='center' ><font size=-1> 抱歉,未找到任何符合您查询条件的信息,请重新选择合适的关键词进行查询.</font></p>"
else
%>
<table width="98%" align="center" cellspacing="0" cellpadding="0" border="0">
<tr>
<td style=line-height:160% bgcolor="#ffffff" width="75%" valign=top><br>
<%=strinfo%>
</td>
<td width="25%" valign=top><br> 这是你发挥的空间!
</td>
</tr>
</table>
<table width="98%" align="center" cellspacing="0" cellpadding="4" border="0">
<tr>
<td align="center">
<br><font size=3><%=strPage%></font>
</td>
</tr>
</table>
<%End If
set strinfo=nothing
%>
<hr size="1" width="760" color="#0000ff">
<div align="center"><font size=-1>
程序更新请到这里<span class="cred">(知识分享论坛)</span>查看</font>
</div>
</BODY>
</HTML>
<%
'采集函数
Function getHTTPPage(url)
On Error Resume Next
dim http
set http=Server.createobject("MSXML2.XMLHTTP")
Http.open "GET",url,false
Http.send()
if Http.readystate<>4 then
exit function
end if
getHTTPPage=bytesToBSTR(Http.responseBody,"GB2312")
set http=nothing
If Err.number<>0 then
Response.Write "<div align='center
一、认识百度搜索
百度搜索,全球最大中文搜索引擎,2005年8月5日在美国纳斯达克上市交易,目前是国内用户使用率最高的搜索引擎,提供网页、新闻、图片、音乐、地图等各种搜索
1、百度网页搜索的查询参数
必备参数
☆ wd--查询的关键词(Keyword)
☆ pn--显示结果的页数(Page Number)
☆ cl--搜索类型(Class),cl=3为网页搜索
可选参数
☆ rn--搜索结果显示条数(Record Number),取值范围在10--100条之间,缺省设置rn=10
☆ ie--查询输入文字的编码(Input Encoding),缺省设置ie=gb2312,即为简体中文
☆ tn--提交搜索请求的来源站点
几个有用的tn
tn=baidulocal 表示百度站内搜索,返回的结果很干净,无广告干扰。比如,在百度站内搜索"快乐",看看返回结果是不是很清爽。
tn=baiducnnic 想把百度放在框架中吗?试试这个参数就可以了,是百度为Cnnic定制的
☆ si--在限定的域名中搜索,比如想在新浪的站内搜索可使用参数si=sina.com.cn,要使这个参数有效必须结合ct参数一起使用。
☆ ct--此参数的值一般是一串数字,估计应该是搜索请求的验证码
si和ct参数结合使用,比如在sina.com.cn中搜索"理想",可用:http://www.baidu.com/baidu?ie=utf-8&am ... n&cl=3&word=理想
☆ bs--上一次搜索的关键词(Before Search),估计与相关搜索有关
2、百度搜索结果页面结构
按源代码结构自上而下为:
搜索框
右侧的火爆地带固定排名
搜索结果
分页区
相关搜索
底部搜索框
版权区
其中"搜索结果、分页区"这两部分就是我们需要的有效数据,根据其代码结果可以发现其唯一的字符串标识,通过这个标识截取内容就可以了,具体看后面的代码。
二、核心函数--使用asp的xmlhttp组件
数据采集程序,俗称小偷程序,其核心部分就是这个xmlhttp组件,用xmlhttp采集数据有些老生常谈了,网上资料也不少,一般的采集代码都是
set http=Server.createobject("MSXML2.XMLHTTP")
Http.open "GET",url,false '打开xmlhttp
Http.send() '发送请求
if Http.readystate<>4 then
exit function
end if
getHTTPPage=bytesToBSTR(Http.responseBody,"GB2312") '返回结果(一般是字节流),并将字节流转换为字符串
set http=nothing '释放xmlhttp
详细应用见下面的完整代码
三、完整代码(文件名:searchi_bd.asp)
<%
option explicit
Dim wd,pn
wd = Request("wd")
pn = Request.QueryString("pn")
'开始错误处理
On Error Resume Next
If Err.Number <> 0 Then
Response.Clear
'显示错误信息给用户
Response.Write "<p align='center' ><font size=3> 出错了,请重新打开百度搜索.</font></p>"
end if
%>
<HTML>
<HEAD>
<TITLE>百度搜索--<%=wd%></TITLE>
</HEAD>
<STYLE type=text/css>
<!--
body,td{font-family:arial}
TD{FONT-SIZE:9pt;LINE-HEIGHT:18px}
.cred{color:#FF0000}
//-->
</STYLE>
<BODY leftmargin="0" topmargin="3" marginwidth="0" marginheight="0">
<table align="center" width="98%" cellspacing="0" cellpadding="0" border="0" bgcolor="#ffffff" >
<tr>
<form name="f1" method="post" action="searchi_bd.asp">
<td width=150 height=50>
你的LOGO
</td>
<td align="left">
<input name=wd size="40" maxlength="100" title="输入关键字,然后Let's Searching..." value="<%=wd%>">
<input type="submit" value=" 百度搜索 ">
</td></form></tr>
</table>
<%
Dim strUrl,strTmp_bd,strInfo,strPage,strPageSum_bd,strQtime_bd
Dim bNoResult_bd,regEx,patrn
'百度查询字符串
strUrl = "http://www.baidu.com/s?ie=gb2312&wd="&wd&am ... &pn&"&cl=3"
'开始采集
strTmp_bd = GetHTTPPage(strUrl)
If InStr(strtmp_bd,"未找到和您的查询")<>0 Then
bNoResult_bd=1
End If
'截取"搜索结果"部分的内容
strinfo = strCut(strTmp_bd,"<DIV id=ScriptDiv></DIV>","<br clear=all>",2)
patrn="</td></tr></table><br>"
Set regEx = New RegExp ' 建立正则表达式。
regEx.Pattern = patrn ' 设置模式。
regEx.IgnoreCase = true
regEx.Global = false
strinfo=regEx.replace(strinfo,"")
'截取"分页区"部分的内容
strPage = strCut(strTmp_bd,"<br clear=all>","<br>",2)
strPage = Replace(strPage,"href=s?","href=searchi_bd.asp?")
'结果数量与用时
strPageSum_bd=strCut(strtmp_bd,"找到相关网页约","篇",2)
if not IsNumeric(strPageSum_bd) then
strPageSum_bd=strCut(strtmp_bd,"找到相关网页","篇",2)
end if
strQtime_bd=strCut(strtmp_bd,"用时","秒",2)
Set strTmp_bd=nothing
%>
<!-- T1-Start -->
<table cellspacing=0 cellpadding=0 border=0 width=98% align="center">
<tr valign=center align=middle height=18>
<td width=1 bgcolor=#999999>
<td nowrap style="FONT-WEIGHT:bold;COLOR:#ffffff;BACKGROUND-COLOR:#0033cc" width=64>互联网</td>
<td align=right bgcolor=#eeeeee><nobr>找到符合<b><%=wd%></b>的相关网页<b><%=strPageSum_bd%></b>篇,用时<b><%=strQtime_bd%></b>秒</nobr> </td>
</tr>
<tr><td bgcolor=#999999 colspan=3 height=2></td></tr></table>
</td>
</tr>
</table>
<%
if wd="" then
Response.Write "<p align='center' ><font size=-1> 您好,请在搜索框中输入关键词.</font></p>"
elseif bNoResult_bd=1 then
Response.Write "<p align='center' ><font size=-1> 抱歉,未找到任何符合您查询条件的信息,请重新选择合适的关键词进行查询.</font></p>"
else
%>
<table width="98%" align="center" cellspacing="0" cellpadding="0" border="0">
<tr>
<td style=line-height:160% bgcolor="#ffffff" width="75%" valign=top><br>
<%=strinfo%>
</td>
<td width="25%" valign=top><br> 这是你发挥的空间!
</td>
</tr>
</table>
<table width="98%" align="center" cellspacing="0" cellpadding="4" border="0">
<tr>
<td align="center">
<br><font size=3><%=strPage%></font>
</td>
</tr>
</table>
<%End If
set strinfo=nothing
%>
<hr size="1" width="760" color="#0000ff">
<div align="center"><font size=-1>
程序更新请到这里<span class="cred">(知识分享论坛)</span>查看</font>
</div>
</BODY>
</HTML>
<%
'采集函数
Function getHTTPPage(url)
On Error Resume Next
dim http
set http=Server.createobject("MSXML2.XMLHTTP")
Http.open "GET",url,false
Http.send()
if Http.readystate<>4 then
exit function
end if
getHTTPPage=bytesToBSTR(Http.responseBody,"GB2312")
set http=nothing
If Err.number<>0 then
Response.Write "<div align='center