百度网盘搜索工具

1.写在前面

经常搜索百度网盘里的资源,以前做了个数据来源来自盘多多,现在不能使用了。所以就又找了一个搜索网站史莱姆http://www.slimego.cn。

2.分析

通过获得查询页面的源数据,得到记录总数,分页数,搜索数据集合。

3.程序实现

下面将贴出实现该程序的关键代码。

 1         /// <summary>
 2         /// 通过正则表达式获得百度网盘文件
 3         /// </summary>
 4         private void GetNetFilesDo()
 5         {
 6             string Keyword = TextBoxKeyword.Text.Trim();
 7             string url = string.Format("http://www.slimego.cn/search.html?q={0}&page=1&rows=20", Keyword);
 8             string html = GetHtmlContent(url);
 9 
10             //获得总页数和总记录数
11             GetPageInfo(html);
12             Invoke(new SetProgressMaxDelegate(SetProgressMax), RecordCount);
13             if (RecordCount <= 0)
14             {
15                 Invoke(new SetButtonStartDelegate(SetButtonStart), true);
16                 return;
17             }
18 
19             //循环页面
20             for (int i = 1; i <= PageCount; i++)
21             {
22                 if (i >= 2)//第1页已经查到了,就不用查了
23                 {
24                     url = string.Format("http://www.slimego.cn/search.html?q={0}&page={1}&rows=20", Keyword, i);
25                     html = GetHtmlContent(url);
26                 }
27 
28                 int seeks = html.IndexOf("<div style=\"display:table\">");//开始位置
29                 int seeke = html.IndexOf("<div id=\"pagesplit\" class=\"m-pagination\"></div>");//结束位置
30                 string content = html.Substring(seeks + 0, seeke - seeks - 15).Trim();
31                 Regex rxGetInfo = new Regex("<div style=\"display: table-cell\" class=\"searchCell\">.*?</div>", RegexOptions.Singleline);
32                 MatchCollection matches = rxGetInfo.Matches(content);
33 
34                 //循环每1页
35                 for (int j = 0; j < matches.Count; j++)
36                 {
37                     if (matches[j].Success)
38                     {
39                         string strMatch = matches[j].Value;
40 
41                         MatchCollection match1 = Regex.Matches(strMatch, "<a rel=\"noreferrer\".*?</a>", RegexOptions.Singleline);//文件名
42                         MatchCollection match2 = Regex.Matches(strMatch, "<span class=\"ftype\">.*?</span>");//类别
43                         MatchCollection match3 = Regex.Matches(strMatch, "<span class=\"size\">.*?</span>");//大小
44                         MatchCollection match4 = Regex.Matches(strMatch, "<span class=\"upload\">.*?</span>");//时间
45                         MatchCollection match5 = Regex.Matches(strMatch, "<a rel=\"noreferrer\".*?</a>", RegexOptions.Singleline);//文件地址
46                         MatchCollection match6 = Regex.Matches(strMatch, "<span class=\"home\">.*?</span>", RegexOptions.Singleline);//分享地址
47                         if (match1 == null || match2 == null || match3 == null || match4 == null || match5 == null || match6 == null) continue;
48 
49 
50                         NetFileInfo file = new NetFileInfo();
51                         file.ID = (i - 1) * PageSize + j + 1;
52                         file.FileFullName = CommonLib.RemoveHTML(match1[0].Value).Trim();
53                         file.FileName = file.FileFullName;
54                         file.ExtName = GetExtName(file.FileFullName);
55                         file.Tag = GetTypeName(file.ExtName);
56                         file.FileSize = CommonLib.RemoveHTML(match3[0].Value);
57                         string TimeSize = CommonLib.RemoveHTML(match4[0].Value);//上传: 2018年07月20日 07时27分
58                         TimeSize = TimeSize.Substring(TimeSize.IndexOf(" ") + 1, TimeSize.LastIndexOf(" ") - 4);
59                         file.FileTime = TimeSize;
60                         file.ShareFileSite = GetShareFileSite(match1[0].Value);
61                         string ShareName = CommonLib.RemoveHTML(match6[0].Value).Replace("查看用户", "").Replace("的所有分享", "");
62                         file.ShareName = ShareName;
63                         file.ShareSite = GetShareSite(match6[0].Value);
64 
65                         Invoke(new GridRowAddDelegate(GridRowAdd), file);
66                         Invoke(new SetProgressDelegate(SetProgress), file.ID);
67                     }
68                 }
69             }
70 
71             Invoke(new SetButtonStartDelegate(SetButtonStart), true);
72         }
View Code

4.程序界面

百度网盘搜索工具

5.功能

1、搜索任意名称的百度网盘共享文件。
2、鼠标左键双击打开网盘地址。
3、鼠标右键点击弹出上下文菜单。打开、复制网盘地址及打开、复制分享者主页。
4、可以导出搜索结果。

下载地址:https://pan.baidu.com/s/16RidPx2VLn7CCUHcQ-aPCw

posted on 2019-09-03 12:33  小熊吉米  阅读(1501)  评论(1编辑  收藏  举报