百度网盘搜索工具

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);//http://m.panduoduo.net/s/name/{0}
 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;//getfilename(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                         //file.disksite = replacedisksite(site.split('|')[0]);
65                         //file.sharesite = site.split('|')[1];
66 
67                         invoke(new gridrowadddelegate(gridrowadd), file);
68                         invoke(new setprogressdelegate(setprogress), file.id);
69                     }
70                 }
71             }
72 
73             invoke(new setbuttonstartdelegate(setbuttonstart), true);
74         }

4 程序界面

5 功能

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

下载地址:https://pan.baidu.com/s/12_c8rfkl56znw8bl9eduea