In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-12 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
The main content of this article is "how to use python to achieve the regional distribution of fans thermal map", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to use python to realize the heat map of fan regional distribution".
Get fan information
The first step is to find the singer's fan page on NetEase Yun's music page:
Through this page, we can get the singer's id.
For example, if Xu Song's id is 31265745, we just need to replace the singer id in the code with Xu Song's id:
# singer idaid = '31265745'
After running the code, we can get the fan information:
After a day and a night of crawlers, more than 40,000 fan messages were obtained.
There are three attribute information, including nickname (nickname), location (location), and gender (gender). We only focus on location information.
It is worth noting that Python3 is not encoded in the same way as Python2, so we need to make some changes in line 95 and line 97 of the original code:
Cipher = AES.new (key.encode ('utf-8'), AES.MODE_CBC, iv.encode (' utf-8')) # encrypted data of type bytes encryptedbytes = cipher.encrypt (msg.encode ('utf-8'))
Make a regional thermal map
In the information extracted from the fan information, the location information is the city code.
Let's go in three steps:
Let's first convert the city code into Chinese location information.
Then convert the Chinese position into latitude and longitude through Baidu API
Mark the thermal points on the longitude and latitude of the map according to the number of people in each area.
In step 2, we need to apply for the service key of Baidu Maps.
My application information is as follows:
Fill in the applied ak into line 75 of the original code.
There is another code change that needs to be made, because if you run the program after you get the ak, you will get an error:
{"status": 240,240, "message": "APP service is disabled"}
Due to the service upgrade, the body of the requested URL has changed after the update:
# Old: http://api.map.baidu.com/geocoder/v2/?location=34.35555,107.32518&output=json&ak= your AK&pois=1# new: http://api.map.baidu.com/reverse_geocoding/v3/?ak= your AK&output=json&coordtype=wgs84ll&location=31.225696121.49884
Judging from this code, the version has been upgraded from v2 to v3. If you change the code according to v3, you will still report an error.
After careful consideration, I found that the new version will be reverse geocoding, and what we need is "positive" geocoding, so I tried to remove the reverse from reverse_geocoding, but unexpectedly passed! How witty.
This part of the code is (starting at line 72 of the original code):
Url = "http://api.map.baidu.com/geocoding/v3/"output = 'json'# key needs to apply to Baidu developer platform for ak=' bwLDdZXZNcrGCLVdsRPVESQv1GjtwOW8'addr = quote (address) uri = url +'? + 'ak=' + ak +' & output=' + output +'& address=' + addr
Finally, it is to draw maps. After many attempts, the application category of Baidu Maps service previously applied for is not a server, so I applied for a browser-side ak:
When locating the area, there was an error all the time, that is, "Huaibei City", so I deleted it from the dictionary:
Loc_counts.pop ('Huaibei City')
Final effect picture
Well, after a period of time and the code, I finally got the thermal map:
It can be seen that Xu Song's fans are mainly concentrated in Anhui, Jiangsu, Shanghai and other places, in addition, there are also many in Guangdong and Beijing.
Zoom in and see:
At this point, I believe you have a deeper understanding of "how to use python to achieve fan regional distribution thermal map". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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: 222
*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.