import
requests
import
json
class
TFT():
def
__init__(
self
):
self
.headers
=
{
'User-Agent'
:
'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36'
}
def
lol_unescape(
self
,t):
t
=
t.replace(
"'"
,
"\'"
)
t
=
t.replace(
"</p>"
,
"}"
)
t
=
t.replace(
"<p>"
, "")
t
=
t.replace(
"<\/p>"
, "")
return
t
def
maopao(
self
,
list
):
length
=
len
(
list
)
for
i
in
range
(length
-
1
):
for
j
in
range
(length
-
i
-
1
):
if
int
(
list
[j][
'sortID'
]) >
int
(
list
[j
+
1
][
'sortID'
]):
list
[j],
list
[j
+
1
]
=
list
[j
+
1
],
list
[j]
return
list
def
get_strategy(
self
,listID):
res
=
requests.get(
"https://lol.qq.com/act/a2016Activity/data/ProdDetail_66_"
+
listID
+
".js"
, headers
=
self
.headers)
text
=
take_middle_text(res.text,
"var ProdDetail_66_"
+
listID
+
"="
,
"}]}};"
)
+
"}]}}"
text
=
TFT.lol_unescape(
self
,text)
j
=
json.loads(text)
text
=
j[
'msg'
][
'detail'
][
'sProdDetail'
]
text
=
text.replace(
"\'"
,
"\""
)
j
=
json.loads(text)
lineup_name
=
j[
'lineup_name'
]
author_name
=
j[
'author_name'
]
hero_location
=
j[
'hero_location'
]
early_heros
=
j[
'early_heros'
]
metaphase_heros
=
j[
'metaphase_heros'
]
if
'level_3_heros'
in
str
(j):
level_3_heros
=
j[
'level_3_heros'
]
else
:
level_3_heros
=
""
if
'hero_replace'
in
str
(j):
hero_replace
=
j[
'hero_replace'
]
else
:
hero_replace
=
""
early_info
=
j[
'early_info'
]
d_time
=
j[
'd_time'
]
equipment_info
=
j[
'equipment_info'
]
location_info
=
j[
'location_info'
]
enemy_info
=
j[
'enemy_info'
]
_time
=
j[
'_time'
]
strategy
=
{
'lineup_name'
:lineup_name,
'author_name'
:author_name,
'hero_location'
:hero_location,
'early_heros'
:early_heros,
"metaphase_heros"
:metaphase_heros,
'level_3_heros'
:level_3_heros,
'hero_replace'
:hero_replace,
'early_info'
:early_info,
'd_time'
:d_time,
'equipment_info'
:equipment_info,
'location_info'
:location_info,
'enemy_info'
:enemy_info,
"_time"
:_time}
return
strategy
def
get_lineName(
self
,setID):
res
=
requests.get(
"https://lol.qq.com/act/AutoCMS/publish/LOLAct/TFTLineup_set3/TFTLineup_set3_"
+
setID
+
".js"
,headers
=
self
.headers)
text
=
take_middle_text(res.text,
"(function(factory){if(typeof window.TFTLineup_set3_"
+
setID
+
"==='undefined'){window.TFTLineup_set3_"
+
setID
+
"=factory();}else{console.error('CMS Error: TFTLineup_set3_"
+
setID
+
" already defined.');}})(function(){return "
,
";});/"
)
j
=
json.loads(text)
return
j[
'line_name'
]
def
get_linelist(
self
):
res
=
requests.get(
"https://lol.qq.com/act/AutoCMS/publish/LOLAct/TFTlinelist_new_set3/TFTlinelist_new_set3.js"
, headers
=
self
.headers)
text
=
take_middle_text(res.text,
"(function(factory){if(typeof window.TFTlinelist_new_set3_List==='undefined'){window.TFTlinelist_new_set3_List=factory();}else{console.error('CMS Error: TFTlinelist_new_set3_List already defined.');}})(function(){return "
,
";});/"
)
j
=
json.loads(text)
linelist
=
[]
for
i
in
j:
d
=
dict
.fromkeys((
'season'
,
'edition'
,
'quality'
,
'pub_time'
,
"sortID"
,
'line_id'
,
'line_name'
))
d[
'season'
]
=
j[
str
(i)][
"season"
]
d[
'edition'
]
=
j[
str
(i)][
"edition"
]
d[
'quality'
]
=
j[
str
(i)][
"quality"
]
d[
'pub_time'
]
=
j[
str
(i)][
"pub_time"
]
d[
'sortID'
]
=
j[
str
(i)][
"sortID"
]
d[
'line_id'
]
=
j[
str
(i)][
"line_id"
]
d[
'extend'
]
=
j[
str
(i)][
"extend"
]
d[
'line_name'
]
=
TFT.get_lineName(
self
,i)
if
d[
'sortID'
] !
=
'
' and d['
extend
'] =='
1
':
linelist.append(d)
return
TFT.maopao(
self
,linelist)
def
get_chess(
self
):
res
=
requests.get(
"https://game.gtimg.cn/images/lol/act/img/tft/js/chess.js"
,headers
=
self
.headers)
j
=
json.loads(res.text)
j
=
j[
'data'
]
chess
=
[]
for
i
in
j:
d
=
dict
.fromkeys((
'chessId'
,
'title'
,
'name'
,
'displayName'
,
"raceIds"
,
'raceIds'
,
'jobIds'
,
'price'
,
'skillName'
,
'skillType'
,
'skillIntroduce'
,
'skillDetail'
,
'magic'
,
'startMagic'
,
'armor'
,
'spellBlock'
,
'attackMag'
,
'attackSpeed'
,
'attackRange'
,
'crit'
,
'TFTID'
,
'recEquip'
,
'proStatus'
,
'races'
,
'jobs'
,
'attackData'
,
'lifeData'
))
d[
'chessId'
]
=
i[
'chessId'
]
d[
'title'
]
=
i[
'title'
]
d[
'name'
]
=
i[
'name'
]
d[
'displayName'
]
=
i[
'displayName'
]
d[
'raceIds'
]
=
i[
'raceIds'
]
d[
'jobIds'
]
=
i[
'jobIds'
]
d[
'price'
]
=
i[
'price'
]
d[
'skillName'
]
=
i[
'skillName'
]
d[
'skillType'
]
=
i[
'skillType'
]
d[
'skillImage'
]
=
i[
'skillImage'
]
d[
'skillIntroduce'
]
=
i[
'skillIntroduce'
]
d[
'skillDetail'
]
=
i[
'skillDetail'
]
d[
'magic'
]
=
i[
'magic'
]
d[
'startMagic'
]
=
i[
'startMagic'
]
d[
'armor'
]
=
i[
'armor'
]
d[
'spellBlock'
]
=
i[
'spellBlock'
]
d[
'attackMag'
]
=
i[
'attackMag'
]
d[
'attackSpeed'
]
=
i[
'attackSpeed'
]
d[
'attackRange'
]
=
i[
'attackRange'
]
d[
'crit'
]
=
i[
'crit'
]
d[
'TFTID'
]
=
i[
'TFTID'
]
d[
'recEquip'
]
=
i[
'recEquip'
]
d[
'proStatus'
]
=
i[
'proStatus'
]
d[
'races'
]
=
i[
'races'
]
d[
'jobs'
]
=
i[
'jobs'
]
d[
'attackData'
]
=
i[
'attackData'
]
d[
'lifeData'
]
=
i[
'lifeData'
]
chess.append(d)
return
chess
def
get_equip(
self
):
res
=
requests.get(
"https://game.gtimg.cn/images/lol/act/img/tft/js/equip.js"
,headers
=
self
.headers)
j
=
json.loads(res.text)
j
=
j[
'data'
]
equip
=
[]
for
i
in
j:
d
=
dict
.fromkeys((
'equipId'
,
'type'
,
'name'
,
'effect'
,
'keywords'
,
'formula'
,
'imagePath'
,
'TFTID'
,
'jobId'
))
d[
'equipId'
]
=
i[
'equipId'
]
d[
'type'
]
=
i[
'type'
]
d[
'name'
]
=
i[
'name'
]
d[
'effect'
]
=
i[
'effect'
]
d[
'keywords'
]
=
i[
'keywords'
]
d[
'formula'
]
=
i[
'formula'
]
d[
'imagePath'
]
=
i[
'imagePath'
]
d[
'TFTID'
]
=
i[
'TFTID'
]
d[
'jobId'
]
=
i[
'jobId'
]
equip.append(d)
return
equip
def
get_job(
self
):
res
=
requests.get(
'https://game.gtimg.cn/images/lol/act/img/tft/js/job.js'
,headers
=
self
.headers)
j
=
json.loads(res.text)
j
=
j[
'data'
]
job
=
[]
for
i
in
j:
d
=
dict
.fromkeys((
'jobId'
,
'name'
,
'introduce'
,
'alias'
,
'level'
,
'TFTID'
,
'imagePath'
))
d[
'jobId'
]
=
i[
'jobId'
]
d[
'name'
]
=
i[
'name'
]
d[
'introduce'
]
=
i[
'introduce'
]
d[
'alias'
]
=
i[
'alias'
]
d[
'level'
]
=
i[
'level'
]
d[
'TFTID'
]
=
i[
'TFTID'
]
d[
'imagePath'
]
=
i[
'imagePath'
]
job.append(d)
return
job
def
get_race(
self
):
res
=
requests.get(
'https://game.gtimg.cn/images/lol/act/img/tft/js/race.js'
,headers
=
self
.headers)
j
=
json.loads(res.text)
j
=
j[
'data'
]
race
=
[]
for
i
in
j:
d
=
dict
.fromkeys((
'raceId'
,
'name'
,
'introduce'
,
'alias'
,
'level'
,
'TFTID'
,
'imagePath'
))
d[
'raceId'
]
=
i[
'raceId'
]
d[
'name'
]
=
i[
'name'
]
d[
'introduce'
]
=
i[
'introduce'
]
d[
'alias'
]
=
i[
'alias'
]
d[
'level'
]
=
i[
'level'
]
d[
'TFTID'
]
=
i[
'TFTID'
]
d[
'imagePath'
]
=
i[
'imagePath'
]
race.append(d)
return
race
def
take_middle_text(txt,txt_s,txt_e
=
'',seeks
=
0
,seeke
=
0
):
try
:
if
txt_e
or
seeks
or
seeke:
pass
else
:
raise
1
s_1
=
txt.find(txt_s)
if
s_1
=
=
-
1
:
raise
1
l_1
=
len
(txt_s)
if
txt_e:
s_2
=
txt.find(txt_e,s_1)
if
s_1
=
=
-
1
or
s_2
=
=
-
1
:
return
False
return
txt[s_1
+
l_1:s_2]
if
seeks:
return
txt[s_1
-
seeks:s_1]
if
seeke:
return
txt[s_1
+
l_1:s_1
+
l_1
+
seeke]
except
:
return
'传参错误或未找到传参文本'
def
main():
tft
=
TFT()
chess
=
tft.get_chess()
equip
=
tft.get_equip()
job
=
tft.get_job()
race
=
tft.get_race()
list
=
tft.get_linelist()
for
i
in
list
:
strategy
=
tft.get_strategy(i[
'line_id'
])
print
(i[
'line_name'
],strategy[
'author_name'
],strategy[
'hero_location'
])
if
__name__
=
=
"__main__"
:
main()