在线抓取网页( 克制指数与配合指数(高玩说)的区别)

优采云 发布时间: 2021-11-30 08:14

  在线抓取网页(

克制指数与配合指数(高玩说)的区别)

  

  我睡不着,我很无聊……我会整理一些更有趣的。第一张图

  影响

  

  

  

  破碎的思绪

  

  自从13级以后玩DOTA2的天梯积分,简直是逆流而上,不进则退,室友已经大呼被游戏玩坏了!!结果把游戏删了

  其实我也发现这个游戏不适合我玩……天梯针对的都是各种精选英雄,普通游戏也横行。另外,我很懒,不喜欢看视频。每场比赛平均有 10 人死亡是很常见的。

  废话少说,其实初衷不是针对的(要选最脏的阵容我会告诉你的)

  核心功能

  先说Dotamax(),因为程序的核心是如何抓取DOTA2数据门户提供的英雄数据。

  看完这篇网站,相信大家基本都知道了,大数据和可视化网站都可以用了。我这里用的是“克制指数”和“合作指数”(高万说这个比较靠谱,那我就信了)。

  通过下面的函数获取目标地址的网页内容(我基本都是用字符串处理,DOM分析没问题)

  private string GetWebContent(string Url)

{

string strResult = "";

try

{

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);

//声明一个HttpWebRequest请求

request.Timeout = 30000;

//设置连接超时时间

request.Headers.Set("Pragma", "no-cache");

HttpWebResponse response = (HttpWebResponse)request.GetResponse();

Stream streamReceive = response.GetResponseStream();

Encoding encoding = Encoding.GetEncoding("utf-8");

StreamReader streamReader = new StreamReader(streamReceive, encoding);

strResult = streamReader.ReadToEnd();

}

catch

{

MessageBox.Show("获取信息失败,请检查网络连接");

}

return strResult;

}

  以下是爬取步骤。由于我是第一次做这种申请,请指出时间点。

  A.捕获英雄信息

  一是抢英雄信息。

  目标网址:

  页面分析:

  

半人马战行者

  从这个标签应该很容易找到

  这些字段可用后,可以创建本地缓存或者添加一行记录,具体代码:

  private void getHeros()

{

heroDataTable = new DataTable("heros");

heroDataTable.Columns.Add("英雄名", typeof(string));

//要抓取的URL地址

string Url = "http://www.dotamax.com/hero/";

//得到指定Url的源码

string html = GetWebContent(Url);

string EnName, ChName;

string key;

int index = 0;

//string output = "";

int count = 0;

do

{

key = "onclick=\"DoNav('/hero/detail/";

int i = html.IndexOf(key, index);

if (i == -1)

break;

i += key.Length;

int j = html.IndexOf("/", i);

EnName = html.Substring(i, j - i);

key = "";

i = html.IndexOf(key, j + 1);

i += key.Length;

j = html.IndexOf(" ", i);

ChName = html.Substring(i, j - i);

Ch2En.Add(ChName, EnName);

heroList.Add(ChName);

DataRow dr = heroDataTable.NewRow();

dr["英雄名"] = ChName;

heroDataTable.Rows.Add(dr);

count++;

index = j;

} while (true);

}

  B.爬行约束指数

  根据英雄的名字,到指定的网址抓取限制英雄的英雄列表。

  目标网址:英文英雄名字/

  页面分析:

  

幻影刺客

3.19%

56.96%

292445

  页面有一大段评论干扰(不知道是不是特意设置成不在乎),反正注意跳过,别抓错了

  从这个标签中查找

  这样,如果你选择了你身边的克制英雄,就加上相应的克制指数。然后按这个值排序并给出建议。具体代码:

  private void addAntiIndex(string hero,int no)

{

no++;

string CurEnName = Ch2En[hero];

string CurChName = hero;

string Url = "http://www.dotamax.com/hero/detail/match_up_anti/" + CurEnName + "/";

//得到指定Url的源码

html = GetWebContent(Url);

string AntiName, AntiValue, WinRate, UsedTime;

string key;

int index = 0;;

do

{

key = "";

int i = html.IndexOf(key, index);

if (i == -1)

{

autoSorting();

return;

}

i += key.Length;

int j = html.IndexOf("", i);

AntiName = html.Substring(i, j - i);

key = "";

i = html.IndexOf(key, j + 1);

i += key.Length;

j = html.IndexOf("", i);

AntiValue = html.Substring(i, j - i);

//去除反抓取

j = html.IndexOf("-->", j);

key = "";

i = html.IndexOf(key, j + 3);

i += key.Length;

j = html.IndexOf("", i);

WinRate = html.Substring(i, j - i);

key = "";

i = html.IndexOf(key, j + 1);

i += key.Length;

j = html.IndexOf("", i);

UsedTime = html.Substring(i, j - i);

index = j;

AntiValue = AntiValue.Substring(0, AntiValue.Length - 1);

double value = Convert.ToDouble(AntiValue);

int t_no = findHero(AntiName);

heroDataTable.Rows[t_no][no] = -value;

double sum = 0;

for (int h = 2; h < 12; h++)

{

sum += (double)heroDataTable.Rows[t_no][h];

}

heroDataTable.Rows[t_no][1] = sum;

} while (true);

}

  C.爬行协调指数

  根据英雄名字,到指定网址抓取匹配英雄的英雄列表。

  目标网址:英文英雄名字/

  页面与上一步基本一致,这里不再赘述。

  目的是找到

  这样,在克制对立的基础上,继续结合队友选择的英雄,选出最多XXX的阵容。具体代码:

  private void addCombIndex(string hero, int no)

{

no++;

string CurEnName = Ch2En[hero];

string CurChName = hero;

string Url = "http://www.dotamax.com/hero/detail/match_up_comb/" + CurEnName + "/";

//得到指定Url的源码

html = GetWebContent(Url);

string CombName, CombValue, WinRate, UsedTime;

string key;

int index = 0; ;

do

{

key = "";

int i = html.IndexOf(key, index);

if (i == -1)

{

autoSorting();

return;

}

i += key.Length;

int j = html.IndexOf("", i);

CombName = html.Substring(i, j - i);

key = "";

i = html.IndexOf(key, j + 1);

i += key.Length;

j = html.IndexOf("", i);

CombValue = html.Substring(i, j - i);

//去除反抓取

j = html.IndexOf("-->", j);

key = "";

i = html.IndexOf(key, j + 3);

i += key.Length;

j = html.IndexOf("", i);

WinRate = html.Substring(i, j - i);

key = "";

i = html.IndexOf(key, j + 1);

i += key.Length;

j = html.IndexOf("", i);

UsedTime = html.Substring(i, j - i);

index = j;

CombValue = CombValue.Substring(0, CombValue.Length - 1);

double value = Convert.ToDouble(CombValue);

int t_no = findHero(CombName);

heroDataTable.Rows[t_no][no] = value;

double sum = 0;

for (int h = 2; h < 12; h++)

{

sum += (double)heroDataTable.Rows[t_no][h];

}

heroDataTable.Rows[t_no][1] = sum;

} while (true);

}

  D. 简单的搜索和排序

  这似乎没什么好说的。

  写在最后

  我已经使用txt文件和MS-SQL(VS更方便)来缓存网页数据。不过为了简化安装,方便朋友们测试,我写了一个在线绿色版,即:分析显示,所有数据只存储在变量中,只占用部分内存,不生成任何缓存文件,并且整个程序只有一个exe文件。

  当然,C#程序还是需要提前有.net框架的,但是作为CS专业的小伙伴,确实没有安装.NET,所以也没什么好抱怨的。

  

  不过也有响应速度慢的问题,因为除了在启动程序的时候把所有的英雄信息都导入到内存中,每增加一个英雄,也会捕捉到克制/合作信息。反正我一定要用离线版拉,不然没时间选英雄和统计,不过大家真的想快点换,看着爬到的数据填满数据库,感觉不错:P

  其实最大的问题就是手动添加英雄太麻烦了,不过貌似只有RPG版的DOTA2才能作为Lua插件使用。。。反正我真不知道DOTA是怎么做的插件与游戏互动。所以只能做成“DOTA2英雄配对助手”,而不是“肮脏的DOTA2插件”……如果有人知道请告诉我~那我还是想做个XXXX插件。(模式识别的朋友们,再见!)

  Dota2Aid 在线绿色版:

  (已到期)

  (不知道帮助有没有说清楚,应该可以用)

  好了,说好开源,VS2012项目文件:

  由于我使用的是本地数据库版本,可能在线版本存在一些未修复的bug。原谅我懒得改了……反正我是觉得响应速度秒杀我,真的不会用这个。

  继续求多玩盒子的交互原理……

  最后,还包括一个 MS-SQL 服务监视器。如果你是本地数据库,可以正常使用~

  

  【C#】WinForm的SQL Server服务监控(避免开机后启动服务):

0 个评论

要回复文章请先登录注册


官方客服QQ群

微信人工客服

QQ人工客服


线