How to use Python to retrieve mobile APP data
Set the proxy through the mobile phone, and then start the packet capture tool on the PC to get the data packet, and then write python code (get mode) to request the data
Last time, some fans said that it was an ios phone. Android phones now need root permission to install certificates. So today, I will not take mobile phones as an exampleA PC is used as an exampleSo that everyone can try it
Today we will teach you how to write Python code to construct data packets after catching post data packets. Here we will explain how to obtain the number of views, likes and views of “wechat official number” articles. (The reason why this example is mainly a little difficult, so I will share this technology with you.)
1 Packet capture tool
Again, Fiddler is used here
Why use a package capture tool instead of just copying the link to the article and collecting it in the browser?
Because you can’t see the number of views, likes, and views in the browser
Therefore, packet capture is adopted here
1. Configuration Fiddler
The port number is set to 8888
Set the domain name filter here, the purpose is to view only the domain name packets that need to be viewed
2. Install the certificate
Click the first one to install the certificate on your PC, and Fiddler can grab HTTPS packets
2 PC agent
In Settings – proxy, set the corresponding IP address and port (here IP is native IP 127.0.0.1, and the corresponding port in Fiddler)
Now you can start capturing packets
3 The packet capture starts
Open the wechat public account article on the PC, for example
Open Fiddler and see the packets
For example, in the original text, reading number: 576, likes: 20, watching: 5
Json data returned by the packet
4 Programming to construct a Post request
After catching the packet, we can know the cookies, forms, request links and other information
Before we start writing the code, let me give you a general idea of what data we need to use (there are many parameters in the form, but most of them are not needed)
The request header (instead of cookie here), user-agent, emulates the mobile browser
# target url
origin_url= "http://mp.weixin.qq.com/mp/getappmsgext"
headers = {
"Cookie": yourcookie,
"User-Agent": "Mozilla / 5.0 (Windows NT 6.1; WOW64) AppleWebKit / 537.36 (KHTML, Like Gecko) Chrome/39.0.2171.95 Safari/537.36 MicroMessenger/6.5.2.501 NetType/WIFI WindowsWechat QBCore/3.43.27.400 QQBrowser / 9.0.2524.400"
}
Copy the code
Here are three of the parameters required by the request.
data = {
"is_only_read": "1"."is_temp_url": "0"."appmsg_type": "9".We can't get like_num without adding it
}
Copy the code
The rest of the parameters (each parameter has its own description)
### the same public account, this will not change
your__biz =""
### Every article has a different MID
article_mid=""
### Every article has a different SN
article_sn=""
# # # remains the same
article_idx="1"
### is valid for dozens of minutes, after which it needs to be updated again
yourappmsg_token="1108_eNbZz5PR1hNkY3Duto6YbmYgGkvHMZaVbiPUGLsS53iccow77rh73HxzFPHQby1-Lw8AqItVlg_d96MU"
Copy the code
To construct the request
origin_url = "https://mp.weixin.qq.com/mp/getappmsgext?"
appmsgext_url = origin_url + "__biz={}&mid={}&sn={}&idx={}&appmsg_token={}&x5=1".format(your__biz, article_mid, article_sn, article_idx, yourappmsg_token)
content = requests.post(appmsgext_url, headers=headers, data=data).json()
print(content)
print(content["appmsgstat"] ["read_num"], content["appmsgstat"] ["old_like_num"],content["appmsgstat"] ["like_num"])
Copy the code
You can see that the post has been successfully sent, and extract the corresponding number of views, likes, and views
5 extension
If the same public account needs to obtain the data of other articles, it only needs to change mid and SN. The links of different articles are shown in the figure below
6
summary
This article explains how to climb the PC data (to wechat public number as an example), the process is very detailed, full of dry goods, I hope to play a role in the effect, so that we learn more technology!
Recommended reading
Hand in hand to teach you to realize the real-time analysis of “B station live” bullet screen
Take “B station live broadcast” as an example to realize “real-time” visualization analysis of data
Flask incorporates ECharts for online visualizations, super detailed!
Python real-time acquisition of live barrage data for visual display
Wechat is added to the background of the public account, and the code can be obtained