Don't say much, come directly to the code
# lead Itchat
import itchat
# WeChat login
itchat.login ()
# Get all users (may be all, print out too messy to see)
user = Itchat.get_ Friends ()
The initial operation is not complicated, and a few lines of code get all the users
But all users can not be used directly, need to get the specified value
# I'm here to scan the user himself for example
# take out the first paragraph in user (that is, the user himself)
i = str (user[:1])
print (i)
# str (), because it has to be processed below (the length of I is 1 if not converted) , cannot be processed further)
# print (len (user[:1]))
# Just to eliminate some side corners, you can omit
info = i[8:-2]
print (info)
The above ' info ' can be omitted, why I have to write it.
Because I thought that after elimination can be converted to JSON format, are tears ...
loads (),eval () have tried, leave a hole, to pass by the teacher for advice.
Import re
# Use the regular method to extract value
# below explain this structure
name = str (re.findall r "' Nickname ': ' (. +?) '", info)) [2:-2]
UIn = str (Re.findall (r "' UIn ': (. +?),", info)) [2:-2]
# print (name)
# print (UIn)
Re.findall (), parameters are regular expressions and processing strings
Regular format I don't have to say more.
r "' Nickname ': ' (. +?) '", processing ' nickname ': ' beginning and ' end of intermediate data
Converted to a string for slicing
Slicing is because re.findall () after processing will let value plus ['], I do not need this format (if necessary to adjust themselves)
Complete code presentation (for reference only):
Import itchat
import re
itchat.login ()
user = Itchat.get_friends ()
i = str (user[:1))
print (i)
info = i[8:-2]
print (info)
name = str (Re.findall (r "' Nickname ': ' (. +?) '", info)) [2:-2]
sign = str ( Re.findall (r "' Signature ': ' (. +?) '", info)) [2:-2]
sex = str (Re.findall (r "' Sex ': (. +?),", info)) [2:-2]
UIn = STR (Re.findall (r "' UIn ': (. +?),", info)) [2:-2] Print (name) print (sex) print (
UIn)
I hope I can help you solve your problems.
Come on, mutual encouragement.