制作思路
- 導(dǎo)入微信庫ichat,中文分詞庫jieba
- 跳出登陸二維碼,掃碼登陸
- 獲取好友列表
- 構(gòu)建所有好友個(gè)性簽名組成的大列表tList
- 對個(gè)性簽名進(jìn)行中文分詞
- 導(dǎo)入imageio庫中的imread函數(shù),并用這個(gè)函數(shù)讀取本地圖片,作為詞云形狀圖片
- 導(dǎo)入詞云制作庫wordcloud
- 構(gòu)建并配置詞云對象w,注意要加scale參數(shù),提高清晰度
- 顯示詞云圖片,并保存到本地
# 導(dǎo)入微信庫ichat,中文分詞庫jieba
import
itchat
import
jieba
# 先登錄微信,跳出登陸二維碼
itchat
.
login
(
)
tList
=
[
]
# 獲取好友列表
friends
=
itchat
.
get_friends
(
update
=
True
)
# 構(gòu)建所有好友個(gè)性簽名組成的大列表tList
for
i
in
friends
:
# 獲取個(gè)性簽名
signature
=
i
[
"Signature"
]
if
'emoji'
in
signature
:
pass
else
:
tList
.
append
(
signature
)
text
=
" "
.
join
(
tList
)
# 對個(gè)性簽名進(jìn)行中文分詞
wordlist_jieba
=
jieba
.
lcut
(
text
,
cut_all
=
True
)
wl_space_split
=
" "
.
join
(
wordlist_jieba
)
# 導(dǎo)入imageio庫中的imread函數(shù),并用這個(gè)函數(shù)讀取本地圖片,作為詞云形狀圖片
import
imageio
mk
=
imageio
.
imread
(
"chinamap.png"
)
# 導(dǎo)入詞云制作庫wordcloud
import
wordcloud
# 構(gòu)建并配置詞云對象w,注意要加scale參數(shù),提高清晰度
my_wordcloud
=
wordcloud
.
WordCloud
(
background_color
=
'white'
,
width
=
1000
,
height
=
700
,
font_path
=
'msyh.ttc'
,
max_words
=
2000
,
mask
=
mk
,
scale
=
20
)
my_wordcloud
.
generate
(
wl_space_split
)
nickname
=
friends
[
0
]
[
'NickName'
]
filename
=
"output11-{}的微信好友個(gè)性簽名詞云圖.png"
.
format
(
nickname
)
my_wordcloud
.
to_file
(
filename
)
# 顯示詞云圖片
import
matplotlib
.
pyplot
as
plt
%
matplotlib inline
plt
.
imshow
(
my_wordcloud
)
plt
.
axis
(
"off"
)
plt
.
show
(
)
print
(
'程序結(jié)束'
)
示例結(jié)果
Getting uuid of QR code.
Downloading QR code.
Please scan the QR code to log in.
Please press confirm on your phone.
Loading the contact, this may take a little while.
Login successfully as 倔強(qiáng) Jarrod
也可以制作城市詞云圖
同理只要將上面代碼中的signature改成city就可以了
for
i
in
friends
:
# 獲取個(gè)性簽名
city
=
i
[
"City"
]
if
'emoji'
in
city
:
pass
else
:
tList
.
append
(
city
)
text
=
" "
.
join
(
tList
)
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯(lián)系: 360901061
您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
