[Python] Just three lines of code to let you know your WeChat friends again! ! !

Three lines of python code let you read your WeChat friends

Before itchat
uploading the code, let's first understand the library used: Itchat is an open source WeChat personal account interface. Using python to call WeChat has never been easier.
This interface shares a similar operation method with the official account interface itchatmp, learning to master two tools at once.
Now that WeChat has become a large part of personal social interaction, I hope this sharing can help you expand your personal WeChat account and facilitate your life.

Not much nonsense on the code:

# 导入itchat库
import itchat

# 登录函数 (enableCmdQR=True  作用是在一段时间内,即使程序跳出,再次进入也不需要重新登录)
itchat.auto_login(enableCmdQR = True)
itchat.dump_login_status()
# 以上实现微信登录,接下来就可以获取微信好友信息啦!

# 采用my_friend变量进行获取好友信息
my_friends = itchat.get_friends(update = True)[:]
# 输出好友数量
print(len(my_friends))
# 遍历好友信息,将想要的字段提取出来,并逐个打印,'NickName'为昵称关键字,可替换
for friend in my_friends:
    print(friend['NickName'])

The above is the code that can simply output your friend's information, how about it? Is not it simple?
Appendix: Other keywords

Key Meaning (value)
UserName User code identification in WeChat system
NickName Friend nickname
Sex gender
Province province
City city
HeadImgUrl Avatar URL in WeChat system
RemarkName Friend's remarks name
Signature Signature

We will introduce more fun little examples about Python in the follow-up, welcome everyone to visit!

Guess you like

Origin blog.csdn.net/qq_24403067/article/details/90213039