大吉大利,今晚吃鸡,让python实现你吃鸡的梦想。

 

 

视频获取:
链接:https://pan.baidu.com/s/1XeCal5szb425eqATcE1F9Q 
提取码:oe1y

效果:大吉大利,今晚吃鸡,让python实现你吃鸡的梦想。_第1张图片

源代码:

import requests
import json
import  jsonpath
import pygal

headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)'
                      'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.92 Safari/537.36'
}
url = 'http://pg.qq.com/zlkdatasys/data_zlk_zlzx.json'
respose  = requests.get(url,headers = headers)
respose.encoding = 'utf-8'
html = respose.text   #网页源代码文本格式
#print(html)

unicodest = json.loads(html)
two = jsonpath.jsonpath(unicodest,'$..yd_c6')#枪的特点
print(two)
three = jsonpath.jsonpath(unicodest,'$..ldtw_f2')#枪的性能
print(three)
four = jsonpath.jsonpath(unicodest,'$..mc_94')  #枪的名字
print(four)
print(four[1:8])
data  = []
num = 0
for a in three:
    if num<7:
        num+=1
        data.append([int(a[0]['wl_45']),int(a[0]['sc_54']),int(a[0]['ss_d0']),int(a[0]['wdx_a7']),int(a[0]['zds_62'])])
        print(data)
radar_chart = pygal.Radar()
radar_chart.title  = '步枪的性能'
radar_chart.x_labels = ['威力','射程','射速','稳定性','子弹数']
for name,property in zip(four[1:8],data):
    radar_chart.add(name,property)
radar_chart.render_to_file('枪支.svg')

你可能感兴趣的:(Python爬虫项目实战)