利用matlab爬虫整理云顶之弈英雄信息

问题描述

https://lolchess.gg是一个很权威的云顶之弈资料站。从这个网站上可以整理出云顶之弈所有英雄的详细资料。可惜是英文网站,且不像OPGG一样有中文版,所以我们爬取的数据只能是英文版的。真是感叹国内居然没有一家网站去认真地去做云顶之弈的资料。

结果展示

利用matlab爬虫整理云顶之弈英雄信息_第1张图片
英雄资料分为14列,分别为名称、费用、种族、职业、生命值、护甲、魔抗、攻击力、攻击范围、攻击速度、初始法力值、法力值、技能描述、技能效果。

源代码

原理在前面的文章中讲过,就不再赘述。这次的爬虫工作量比以前大,但是没有发现新的问题。

a=urlread('https://lolchess.gg/champions/blitzcrank');
b=convertCharsToStrings(a);
name=regexpi(b,'"name":"[\s\S]{1,15}","im','match');
name=strrep(name,'"name":"','');
name=strrep(name,'","im','');
cost=regexpi(b,'"cost":\S{1},"o','match');
cost=strrep(cost,'"cost":','');
cost=strrep(cost,',"o','');
origin=regexpi(b,'"origins":\S{1,20},"','match');
origin=strrep(origin,'"origins":["','');
origin=strrep(origin,'"],"','');
origin=strrep(origin,'"','');
classes=regexpi(b,'"classes":\S{1,16},"','match');
classes=strrep(classes,'"classes":["','');
classes=strrep(classes,'"],"','');
classes=strrep(classes,'","','');
health=regexpi(b,'"health":\S{3,4},"','match');
health=strrep(health,'"health":','');
health=strrep(health,',"','');
armor=regexpi(b,'"armor":\S{2,3},"','match');
armor=strrep(armor,'"armor":','');
armor=strrep(armor,',"','');
magical_resistance=regexpi(b,'"magical_resistance":\S{1,20},"','match');
magical_resistance=strrep(magical_resistance,'"magical_resistance":','');
magical_resistance=strrep(magical_resistance,',"','');
attack_damage=regexpi(b,'"attack_damage":\S{1,20},"','match');
attack_damage=strrep(attack_damage,'"attack_damage":','');
attack_damage=strrep(attack_damage,',"','');
attack_range_slot=regexpi(b,'"attack_range_slot":\S{1},"','match');
attack_range_slot=strrep(attack_range_slot,'"attack_range_slot":','');
attack_range_slot=strrep(attack_range_slot,',"','');
attack_speed=regexpi(b,'"attack_speed":\S{1,5},"','match');
attack_speed=strrep(attack_speed,'"attack_speed":','');
attack_speed=strrep(attack_speed,',"','');
starting_mana=regexpi(b,'"starting_mana":\S{1,20}}}','match');
starting_mana=strrep(starting_mana,'"starting_mana":','');
starting_mana=strrep(starting_mana,'}}','');
cost_mana=regexpi(b,'"cost":\S{1,3},"t','match');
cost_mana=strrep(cost_mana,'"cost":','');
cost_mana=strrep(cost_mana,',"t','');
desc=regexpi(b,'"desc":"[\s\S]{1,300}","sta','match');
desc=strrep(desc,'"desc":"','');
desc=strrep(desc,'","sta','');
stats=regexpi(b,'"stats":[\s\S]{1,150},"i','match');
stats=strrep(stats,'"stats":["','');
stats=strrep(stats,'"],"i','');
stats=strrep(stats,'"','');
A=["名称","费用","种族","职业","生命值","护甲","魔抗","攻击力","攻击范围","攻击速度","初始法力值","法力值","技能描述","技能效果"];
xlswrite('output4.xlsx',A,'A1:N1');
xlswrite('output4.xlsx',name','A2:A58');
xlswrite('output4.xlsx',cost','B2:B58');
xlswrite('output4.xlsx',origin','C2:C58');
xlswrite('output4.xlsx',classes','D2:D58');
xlswrite('output4.xlsx',health','E2:E58');
xlswrite('output4.xlsx',armor','F2:F58');
xlswrite('output4.xlsx',magical_resistance','G2:G58');
xlswrite('output4.xlsx',attack_damage','H2:H58');
xlswrite('output4.xlsx',attack_range_slot','I2:I58');
xlswrite('output4.xlsx',attack_speed','J2:J58');
xlswrite('output4.xlsx',starting_mana','K2:K58');
xlswrite('output4.xlsx',cost_mana','L2:L58');
xlswrite('output4.xlsx',desc','M2:M58');
xlswrite('output4.xlsx',stats','N2:N58');

你可能感兴趣的:(利用matlab爬虫整理云顶之弈英雄信息)