网盘资源搜索的一些知识 C#

针对互联网盘上的资源进行搜索查找。写一个网盘资源搜索的要点主要有以下几点。

1.这个网盘资源搜索的原理就是利用互联网搜索引擎的site 命令。 其次就是针对网页链接进行提取以及处理。

首先就是编写一个类,Helper类,用来保存网页链接地址, 标题 序号等。

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 
 6 namespace Search
 7 {
 8    public class helper
 9     {
10        //序号
11        public int ID { get; set; }
12        //资源的标题
13        public string Title { get; set; }
14        //资源的网址
15        public string ResourceUrl { get; set; }
16     }
17 }

2.再者就是写一个类,用来处理搜索出来的资源的提取,代码如下。

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Windows.Forms;
 6 using System.Text.RegularExpressions;
 7 
 8 namespace Search
 9 {
10    public class wpserver
11     {
12        public string keywords { get; set; }
13        public string wp { get; set; }
14        private  List<helper> list = new List<helper>(); //保存提取的资源标题以及网址
15        public List<helper> GetResource(WebBrowser wb)
16        {
17            for (int i = 1; i <= 50; i++)
18            {
19                HtmlElement hh = wb.Document.GetElementById(i.ToString()); //针对百度搜索结果提取网页查找的资源
20                if (hh == null)
21                {
22                    return list;
23                }
24                string text = hh.InnerText.Substring(0, 30); //截取标题的长度
25                string txtUrl = hh.InnerHtml;
26                MatchCollection ma = Regex.Matches(txtUrl, @"http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?");
27                if (ma.Count >= 1)
28                {
29                    helper h = new helper(); 
30                    h.ID = i;
31                    h.Title = text;
32                    h.ResourceUrl = ma[0].ToString();
33                    list.Add(h);
34                }
35            }
36            return list;
37           
38        }
39 
40      
41     }
42 }

3.最后看看最后的网盘资源搜索 的窗体结果。

 

源代码下载地址: http://download.csdn.net/detail/luoyangwyb/7050227

 

posted @ 2014-03-16 19:36  落日云烟  阅读(553)  评论(0编辑  收藏  举报