使用asp.net或者asp检查某个url地址,某篇文章是否被搜索引擎,如百度,谷歌,搜狗收录。
实现原理:直接搜索你那篇文章的url地址(不带协议,但上协议也行,代码会自动去掉协议内容),如果被索引会返回搜索结果,否则会提示找不到信息。
Asp.Net检查百度,谷歌,搜狗搜索引擎是否收录文章网址源代码:
using System;using System.Net;using System.Text;using System.IO;using System.Web;public class SearchEngineIndex{ public static string[] urls = { //搜索引擎检查地址 "http:///web?ie=utf8&query=") '搜索引擎未索引url地址时的关键字 NoFindKeyword=array("抱歉,没有找到与", "找不到和您的查询", "未收录?") End sub private function GetEncoding(contenttype) contenttype=lcase(contenttype) if instr(contenttype,"gb2312")<>0 and instr(contenttype,"gbk")<>0 then GetEncoding="gb2312" elseif instr(contenttype,"big5")<>0 then GetEncoding="big5" else GetEncoding="utf-8" end if end function private function BinToString(bin,encoding)'将2进制流数据依据编码转为对应的字符串内容 dim obj set obj=Server.CreateObject("Adodb.Stream") obj.Type=1:obj.Mode=3:obj.Open obj.Write bin obj.Position=0:obj.Type=2:obj.Charset=encoding BinToString=obj.ReadText obj.Close:set obj=nothing end function public function GetHtml(url) dim xhr set xhr=server.CreateObject("microsoft.xmlhttp") xhr.open "get",url,false xhr.send encoding=GetEncoding(xhr.getResponseHeader("content-type")) response.CharSet=encoding GetHtml=BinToString(xhr.responsebody,encoding) set xhr=nothing end function public function CheckIndex(url,engin) if len(url)=0 then exit function if engin<0 or engin>2 then engin=1 url=urls(engin)&server.URLEncode(url) dim html html=GetHtml(url) CheckIndex=instr(html,NoFindKeyword(engin))=0 End functionend Classset sei=new SearchEnginIndexresponse.Write sei.CheckIndex("www.jb51.net/article/20101014/2902.aspx",0)'百度索引response.Write sei.CheckIndex("www.jb51.net/article/20101014/2902.aspx",1)'谷歌索引response.Write sei.CheckIndex("www.jb51.net/article/20101014/2902.aspx",2)'搜狗索引set sei=nothing %>