# -*-coding:utf-8-*-
import requests
import json
from wordcloud import WordCloud
# url = 'https://www.feixiaohao.com/'
url = 'https://dncapi.bqiapp.com/api/coin/data_list?webp=1'
headers = {
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/65.0.3325.181 Safari/537.36',
'Referer': "http://www.qukuaiwang.com.cn"
}
data = requests.get(url,headers=headers).content
text = json.loads(data)['data']
i =0
for item in text:
if i < 100:
# print(item['name_zh'])
# print(item['symbol'])
name_zh = item['name_zh']
symbol = item['symbol']
with open('crypto-currency.txt','a') as f:
f.write('%s %s '%(name_zh,symbol))
i +=1
with open("crypto-currency.txt" ,encoding="utf-8")as file:
text_1 = file.read()
w = WordCloud(background_color='black',
width=2700,
font_path='/Library/Fonts/Arial Unicode.ttf',
height=1800).generate(text_1)
image=w.to_image()
image.show()
w.to_file("crypto-currency.png")
图片.png