一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - ASP.NET教程 - Asp.Net、asp實現的搜索引擎網址收錄檢查程序

Asp.Net、asp實現的搜索引擎網址收錄檢查程序

2019-12-07 13:28junjie ASP.NET教程

這篇文章主要介紹了Asp.Net、asp實現的搜索引擎網址收錄檢查程序,即實現檢查一個網址是否被搜索引擎收錄功能的小程序,需要的朋友可以參考下

使用asp.net或者asp檢查某個url地址,某篇文章是否被搜索引擎,如百度,谷歌,搜狗收錄。

實現原理:直接搜索你那篇文章的url地址(不帶協議,但上協議也行,代碼會自動去掉協議內容),如果被索引會返回搜索結果,否則會提示找不到信息。

Asp.Net檢查百度,谷歌,搜狗搜索引擎是否收錄文章網址源代碼:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using System;
using System.Net;
using System.Text;
using System.IO;
using System.Web;
public class SearchEngineIndex
{
  public static string[] urls = { //搜索引擎檢查地址
      "http://www.baidu.com/s?ie=utf-8&wd=",//百度索引url檢查地址
      "https://www.google.com.hk/search?q=",//谷歌索引url檢查地址
      "http://www.sogou.com/web?ie=utf8&query="//搜狗索引url檢查地址
    }
    , noFindKeyword = { "抱歉,沒有找到與", "找不到和您的查詢", "未收錄?" };//搜索引擎未索引url地址時的關鍵字
  /// <summary>
  /// 獲取響應的編碼
  /// </summary>
  /// <param name="contenttype"></param>
  /// <returns></returns>
  private static Encoding GetEncoding(string contenttype)
  {
    if (!string.IsNullOrEmpty(contenttype))
    {
      contenttype = contenttype.ToLower();
      if (contenttype.IndexOf("gb2312") != -1 || contenttype.IndexOf("gbk") != -1) return Encoding.GetEncoding(936);
      if (contenttype.IndexOf("big5") != -1) return Encoding.GetEncoding(950);
    }
    return Encoding.UTF8;
  }
  /// <summary>
  /// 使用HttpWebRequest對象,自動識別字符集
  /// </summary>
  /// <param name="url"></param>
  /// <param name="addUseragent">是否添加UserAgent,采集其他網站時防止被攔截</param>
  /// <returns></returns>
  public static string GetHtml(string url, bool addUseragent)
  {
    HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
    if (addUseragent) request.UserAgent = "Googlebot|Feedfetcher-Google|Baiduspider";
    string html = null;
    try
    {
      HttpWebResponse response = (HttpWebResponse)request.GetResponse();
      StreamReader srd = new StreamReader(response.GetResponseStream(), GetEncoding(response.ContentType));
      html = srd.ReadToEnd();
      srd.Close();
      response.Close();
    }
    catch { }
    return html;
  }
  /// <summary>
  /// 檢查某個url是否被搜索引擎索引
  /// </summary>
  /// <param name="url">url地址</param>
  /// <param name="engin">0:百度 1:谷歌 2:搜狗,其他搜索引擎如bing和360直接查網址顯示的結果不是直接得到網址的,有些出入,不做檢查</param>
  /// <returns></returns>
  public static bool CheckIndex(string url, int engin)
  {
    if (string.IsNullOrEmpty(url)) return false;
    if (engin < 0 || engin > 2) engin = 0;
    url = urls[engin] + HttpUtility.UrlEncode(url.ToLower().Replace("http://", "").Replace("https://", ""));
    bool r = true;
    string html = GetHtml(url, true);
    if (html == null || html.IndexOf(noFindKeyword[engin]) != -1) r = false;
    return r;
  }
}
 
 
 
//調用方法示例
 
    SearchEngineIndex.CheckIndex("m.ythuaji.com.cn/article/20101014/2902.aspx", 0);//檢查百度索引
    SearchEngineIndex.CheckIndex("m.ythuaji.com.cn/article/20101014/2902.aspx", 1);//檢查谷歌索引
    SearchEngineIndex.CheckIndex("m.ythuaji.com.cn/article/20101014/2902.aspx", 2);//檢查搜狗索引

Asp檢查百度,谷歌,搜狗搜索引擎是否收錄文章網址源代碼:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<%
class SearchEnginIndex
 dim urls,noFindKeyword
 private sub Class_Initialize
  '百度,谷歌,搜狗url地址索引查詢地址
  urls=array("http://www.baidu.com/s?ie=utf-8&wd=","https://www.google.com.hk/search?q=","http://www.sogou.com/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 function
end Class
set sei=new SearchEnginIndex
response.Write sei.CheckIndex("m.ythuaji.com.cn/article/20101014/2902.aspx",0)'百度索引
response.Write sei.CheckIndex("m.ythuaji.com.cn/article/20101014/2902.aspx",1)'谷歌索引
response.Write sei.CheckIndex("m.ythuaji.com.cn/article/20101014/2902.aspx",2)'搜狗索引
set sei=nothing
 %>

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 98pao强力打造高清免费 | 欧美老人与小伙子性生交 | 亚洲精品色图 | 欧美高清一区 | h动态图男女啪啪27报 | 九九精品国产亚洲A片无码 九九99热久久999精品 | 出轨同学会2在线观看 | 日韩欧美一区二区三区免费看 | aika跟黑人太猛了 | 久久免费资源福利资源站 | 被调教的校花 | 国产成人精品免费视频软件 | 国产福利兔女郎在线观看 | 满溢游泳池免费土豪全集下拉版 | 国产精品视频第一页 | 精品日本一区二区 | xnxx18美女| 91av爱爱 | 男人在线网址 | 97福利社 | 青柠影视在线播放观看高清 | 色婷婷综合和线在线 | 欧美日韩国产在线人成dvd | 国产精品久久久久久久人人看 | 日日插插| 国产视频久久久 | 欧美一级特黄特色大片免费 | 国产精品午夜性视频网站 | 秋霞黄色片 | 韩国最新理论片奇忧影院 | 亚洲嫩模吧粉嫩粉嫩冒白浆 | 男女一级特黄a大片 | 美女班主任下面好爽好湿好紧 | 国产手机在线αⅴ片无码观看 | 青草网址| 人人爽人人香蕉 | 91午夜剧场 | 亚洲国产三级在线观看 | 国产人成激情视频在线观看 | 窝窝影院午夜色在线视频 | 日本护士撒尿xxxx欧美 |