模板:妖魔(全)
刷
历
编
跳到导航
跳到搜索
头目
妖王
精怪
使用前需安装requests和lxml库:
pip install requests pip install lxml
python代码如下:
import requests
from lxml import etree
# 设置HTTP请求的头部信息,模拟浏览器访问
headers = {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
"Accept-Language": "zh-CN,zh;q=0.9",
"Cache-Control": "no-cache",
"Connection": "keep-alive",
"Pragma": "no-cache",
"Sec-Fetch-Dest": "document",
"Sec-Fetch-Mode": "navigate",
"Sec-Fetch-Site": "same-origin",
"Sec-Fetch-User": "?1",
"Upgrade-Insecure-Requests": "1",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36",
"^sec-ch-ua": "^\\^Not/A)Brand^^;v=^\\^8^^, ^\\^Chromium^^;v=^\\^126^^, ^\\^Google",
"sec-ch-ua-mobile": "?0",
"^sec-ch-ua-platform": "^\\^Windows^^^"
}
def yaomo_():
shouling_list = []
jingguai_list = []
# 爬取首领列表
url = 'https://wiki.biligame.com/wukong/%E6%A8%A1%E6%9D%BF:%E5%AF%BC%E8%88%AA/%E9%A6%96%E9%A2%86'
response = requests.get(url, headers=headers)
parse_html = etree.HTML(response.text)
i = 1
while 1:
# 获取首领的名称和对应的值
k1_list = parse_html.xpath('//div[' + str(i) + '][@class="wk-nav-line"]/div[@class="wk-nav-line-k"]/text()')
v1_list = parse_html.xpath('//div[' + str(i) + '][@class="wk-nav-line"]/div[@class="wk-nav-line-v"]/a/text()')
if not v1_list and not k1_list:
break
for k1 in k1_list:
shouling_list.append({k1: v1_list})
i += 1
# 爬取精怪列表
url = 'https://wiki.biligame.com/wukong/%E6%A8%A1%E6%9D%BF:%E5%AF%BC%E8%88%AA/%E7%B2%BE%E6%80%AA'
response = requests.get(url, headers=headers)
parse_html = etree.HTML(response.text)
i = 1
while 1:
# 获取精怪的名称和对应的值
k1_list = parse_html.xpath('//div[' + str(i) + '][@class="wk-nav-line"]/div[@class="wk-nav-line-k"]/a/text()')
v1_list = parse_html.xpath('//div[' + str(i) + '][@class="wk-nav-line"]/div[@class="wk-nav-line-v"]/a/text()')
if not v1_list and not k1_list:
break
for k1 in k1_list:
jingguai_list.append({k1: v1_list})
i += 1
# 搜索图片并创建最终的列表
final_list = search_picture(shouling_list + jingguai_list)
create_model(final_list)
def search_picture(list):
#查找所有影神图
final_list = []
url = 'https://wiki.biligame.com/wukong/%E7%89%B9%E6%AE%8A:%E6%96%87%E4%BB%B6%E5%88%97%E8%A1%A8'
params = {
"limit": "500",
"ilsearch": '影神图'
}
response = requests.get(url, headers=headers, params=params)
parse_html = etree.HTML(response.text)
name_list = parse_html.xpath('//tr/td[@class="TablePager_col_img_name"]/a/text()')
for i in list:
for key in i:
for j in i[key]:
flag = 0
for z in name_list:
if j in z:
flag = 1
final_list.append([key, j, z])
break
if flag != 1:
final_list.append([key, j, ''])
return final_list
def create_model(list):
# 创建用于展示的字符串
toumu_str = '\n<h2 id="头目">头目</h2>\n\n'
yaowang_str = '\n<h2 id="妖王">妖王</h2>\n\n'
jingguai_str = '\n<h2 id="精怪">精怪</h2>\n\n'
for i in list:
if i[0] == '头目':
if i[2] == '':
i[2] = 'UI-未收录影神图.png'
toumu_str = toumu_str + '{{模板:妖魔展示|名称=' + i[1] + '|影神图=' + i[2] + '}}\n'
if i[0] == '妖王':
if i[2] == '':
i[2] = 'UI-未收录影神图.png'
yaowang_str = yaowang_str + '{{模板:妖魔展示|名称=' + i[1] + '|影神图=' + i[2] + '}}\n'
elif i[0] != '头目' and i[0] != '妖王':
if i[2] == '':
i[2] = 'UI-未收录影神图.png'
jingguai_str = jingguai_str + '{{模板:妖魔展示|名称=' + i[1] + '|影神图=' + i[2] + '}}\n'
toumu_str += '{{clear}}'
yaowang_str += '{{clear}}'
jingguai_str += '{{clear}}'
print('<includeonly>')
print(toumu_str)
print(yaowang_str)
print(jingguai_str)
print('''</includeonly><noinclude>
{{导航|模板}}{{文档}}
</noinclude>''')
if __name__ == '__main__':
yaomo_()

沪公网安备 31011002002714 号