Related to the database code
class JobPositionDao(BaseDao): def __init__(self): super().__init__() # 查询python所有岗位的描述 def findPythonDetail(self): sql = "SELECT jd.detail_desciption FROM `job_position_detail` as jd,`job_position` as jp,`job_collect_task` as jc WHERE jd.detail_positionid=jp.job_id and jp.job_taskid=5;" result = self.execute(sql, params=None) self.commit() return self.fetch() pass
Drawing code
import jieba from day022.spiderproject.spiderproject.dao.jobpositiondao import JobPositionDao import matplotlib.pyplot as plt from wordcloud import WordCloud,ImageColorGenerator import numpy as np from PIL import Image from functools import reduce jp = JobPositionDao() txtList = jp.findPythonDetail() txtList = [i[0] for i in txtList] print(txtList) with open("PythonDetail.txt","w",encoding="utf8") as fp: fp.writelines(txtList) pass with open("PythonDetail.txt","r",encoding="utf8") as fp: txtStr = fp.read() pass with open("StopWords.txt","r",encoding="utf8") as fp: stopWords = fp.read().split(", " ) Pass wordList = jieba.lcut (txtStr) wordList = [W for W in wordList IF W Not in stopwords] # remove stop words wordsStr the reduce = ( the lambda A, B: A + " " + B, wordList) # The word It is connected to a string separated by a space imgMask = np.array (Image.open ( " alice_mask.png " )) wordcloud = wordcloud (MAX_WORDS = 200 is, mask = imgMask, BACKGROUND_COLOR = " White " , font_path = "C: /Windows/Fonts/SIMYOU.TTF " ) .generate (wordsStr) # load the font support Chinese plt.imshow (wordcloud) plt.axis ( ' OFF ' ) plt.show ()
result