In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "Python how to obtain Wechat friend area, gender, signature information and visualization", the content of the article is simple and clear, easy to learn and understand, now please follow the editor's ideas slowly in depth, together to study and learn "Python how to obtain Wechat friend area, gender, signature information and visualization of the result" bar!
The text obtains the friend information according to itchat library.
You can do this with the following two lines of code:
Itchat.auto_login (hotReload=True)
Friends = itchat.get_friends (update=True)
The first line of code is to log in to the Wechat web version using the itchat library, which will pop up the code scan login interface. The purpose of setting the parameter hotReload=True is to exit the program in a short time, so you don't have to scan the code to log in again.
Get_friends () returns a list with n dictionary entries, where n equals your Wechat friends. Since the list type is serializable, we can use the json library to save it to a file
# convert the json object to a string and save it locally in with open ("data.json", "w", encoding= "utf-8") as f: f.write (json.dumps (friends, indent=2, ensure_ascii=False))
The results are as follows:
Extract data and visualize gender information visualization
Use the following code to get the gender information of all your friends.
For friend in friends: if friend ["Sex"] = = 0: unknow + = 1 elif friend ["Sex"] = = 1: male + = 1 else: female + = 1
The result of visualization:
Most of the male students are male students, while the female students account for 1x4. Sure enough, I am a male student with no story.
Gender unknown is a friend who does not have a gender set.
Regional information visualization
Use the following code to get the regional information of all your friends.
Dic_province = dict () for friend in self.friends: key = friend ["Province"] if key not in dic_province.keys (): dic_ Province [key] = 1 else: dic_ Province [key] + = 1 key_list = [] value_list = [] for key Value in dic_province.items (): if key = "": key = "other regions" key_list.append (key) value_list.append (value)
The result of visualization is:
Well, it seems to have exposed my own area.
Visualization of signature information
Use the following code to get the personal signatures of all your friends
All_sign = "" for friend in self.friends: sign = friend ["Signature"] if len (sign) > 0: # filter facial expressions Otherwise it will affect the word cloud emoji = re.findall ("", sign,re.S) if len (emoji) > 0: sign = sign.replace (emoji [0]) "") all_sign = all_sign + sign + "\ n" if os.path.exists ("wc/sign.txt"): os.remove ("wc/sign.txt") with open ("wc/sign.txt", "a +", encoding= "utf-8") as f: f.write (all_sign)
The result of using word cloud visualization is
Haha, it is also a group of friends who are positive and actively explore life.
Other data visualization
The reason is similar, so I won't repeat it.
Operation schematic
Run the main.py file in the root directory of the project to get the gender and region visualization results, as shown below:
If you haven't logged in recently, the program will let you scan the code to log in.
If you need a visual friend signature, you also need to run the wc.py file under the wc folder in the root directory of the project, as shown below:
This word cloud can be customized, as long as you replace the image bc.png under the wc/image in the project root directory, you can modify the background of the word cloud, preferably with a solid color background.
Thank you for reading, the above is the content of "how Python obtains Wechat friend area, gender, signature information and visualization of the result". After the study of this article, I believe you have a deeper understanding of how Python obtains Wechat friend area, gender, signature information and visualization of the result, and the specific use still needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.