非小号数字货币名称生成词云

# -*-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
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容