本帖最后由 wxy1997 于 2020-3-2 20:51 编辑
直接上图和代码吧
from urllib import request
import sys
import urllib.request
import json
from bs4 import BeautifulSoup as bs
response = urllib.request.urlopen("http://pvp.qq.com/web201605/js/herolist.json")
hero_json = json.loads(response.read())
print("----------------------------王者荣耀英雄克制关系查询--------------------------------")
name = input("请输入你要查询的英雄名字:")
num = 0
for i in hero_json:
hero_name = i['cname']
ename = i['ename']
if hero_name == name: #根据英雄名字获取对应的编号
num = ename
break
if num == 0:
print("您输入的英雄不存在哦")
sys.exit(0)
page = urllib.request.urlopen("https://pvp.qq.com/web201605/herodetail/" + str(num) + ".shtml")
htmlCode = page.read()
htmlCode = bs(htmlCode, 'html.parser')
tx = htmlCode.select(".hero-list-desc")
print("\n--------------最佳搭配英雄:--------------")
print(tx[0].find_all('p')[0].string)
print(tx[0].find_all('p')[1].string + '\n')
print("--------------压制英雄:------------------")
print(tx[1].find_all('p')[0].string)
print(tx[1].find_all('p')[1].string + '\n')
print("--------------被压制英雄:------------------")
print(tx[2].find_all('p')[0].string)
print(tx[2].find_all('p')[1].string)
studyPython.rar
(1.79 KB, 下载次数: 6)
python入门教程 : https://www.wenshushu.cn/f/1y1u1iwcd60 |