This is the 8th day of my participation in the August More text Challenge. For details, see: August More Text Challenge

Hello, everyone! I’m A Chen. Today, I’m going to teach you how to grab the personal history playback data of “a cool video” on the PC and visualize it

Last time, some fans said that it was an ios phone, android phone now need root permission to install the certificate, so today, not mobile phone as an example, take PC as an example, so that everyone can start to try

Today, we will teach you how to write Python code to construct the data packet after catching the data packet (you need the token to get the data). Here, we will take “some cool video” as an example to obtain the personal history video data, and make a visual data display

1 Packet capture tool

Fiddler is a PC packet capture tool. If you don’t have it, you can reply to “Fiddler” on your official account to get the installation package.

1. Configuration Fiddler

The port is set to 8888

Once you’re done, click Actions to make the Settings take effect

The filter domain name is set here, in order to view only the domain name packets that need to be viewed

2. Install the certificate

Click on the first to install the certificate on your PC and Fiddler grabs HTTPS packets

2 PC proxy

In Settings – Proxy, set the IP address and port (in this case, IP is the local IP 127.0.0.1, and the corresponding port in Fiddler).

Then you can start to capture packets

3 Start packet capture

Open a cool video software on the PC, click on the history play, and view the record

You can see the historical playback video

Once opened, Fiddler can see the packet

Json data returned by the corresponding packet

4 Programmatically construct requests

After capturing the packet, we can know the cookie, request link and other information

If there is no cookie and other information may appear the following situation!

Request links can be pasted directly

To get a cookie

In the request header (replace cookie here), the user-agent is impersonating the client

# target url
origin_url = "Https://playlog.youku.com/playlog/open/get.json?appName=iKu&appVersion=7.9.5&appkey=NWKOm6ipixT2f4Rs&ccode=03010101+&cl IentDrmAbility = 7 & deviceName = iKu&deviceid = 54 ab3a599713 & hwClass = 1 & isOpenControl = 1 & os_ver = win_10. 0 _64 & pg = 1 & p z = 100 & sign = a41d 7247936a5bb7c076a6992d311921&stoken=UtDB1C4gT9Kg5h2crX7Cy2oZfJqIo2Zwj7rPYW9QZGyzOzN2Zzv14TQYGah0hxzGKESK1PElUp92d93yxZaC C6Ej8XBFCbv6arPpzNLTOQbS%252B0rBf8mB7TzAoLYekkTK4XmocdKt3OxACcMwchQZWQ%253D%253D&time=1618191263&utdid=YB5DqwAAACkDAIwqs B2Ux2P8 & ver = 8.0.8.12173"
 
 
# Add Cookie to avoid login operations, where "user-agent" is best as the client id
yourcookie="Own cookie"
headers = {
    "Cookie": yourcookie,
    "User-Agent": "IKU / 8.0.8.12173; IKUCID/IKU; OS/win_10. 0 _64; IKUCID/IKU"
}
Copy the code

To construct the request

content = requests.post(origin_url, headers=headers).json()
results = content['results']
print(content)
print(results)
print(len(results))
with open("lyc0412.txt".'w+',encoding="utf-8") as f:
    for i in results:
            print("Type ="+i['category'])
            print("Player device =" + i['devicename'])
            print("Title =" + i['title'])
            print("Time =" + i['pubdate'])
            print("-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --")
            f.write(str(i['category']) +"="+str(i['devicename']) +"="+str(i['title']) +"="+str(i['pubdate']) +"\n")
Copy the code

You can see that it has been successfully sent, and the corresponding data has been extracted. This time, the data is not saved to Excel, but directly stored in a text file (separated by “=”).

5 Visual presentation

1. Type display

The number of types in the viewing history is calculated

Look at the data first

for i in data:
    temdata.append(i.split("=") [0])
name = list(set(temdata))
value = [temdata.count(k) for k in name]
c = (
    Pie()
        .add(
        ""[list(z) for z in zip(name, value)],
        # The center of the pie chart. The first item in the array is the x-coordinate and the second is the y-coordinate
        When set to %, the first item is relative to the container width and the second is relative to the container height
        center=["35%"."50%"],
    )
        .set_colors(["blue"."green"."yellow"."red"."pink"."orange"."purple"])  # Set color
        .set_global_opts(
        title_opts=opts.TitleOpts(title="Type presentation"),
        legend_opts=opts.LegendOpts(type_="scroll", pos_left="70%", orient="vertical"),  Adjust the legend position
    )
        .set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}"))
        .render("Type display.html"))Copy the code

2. Play the device display

Count the number of playback device types (since the code is similar to the above code, only the different parts of the code are shown here)

temdata = []
for i in data:
    temdata.append(i.split("=") [1])
name = list(set(temdata))
value = [temdata.count(k) for k in name]
Copy the code

3. Statistical presentation of film years

The number of films and TV shows in 2020, 2019, 2018 and other years in the broadcast history is counted

We just need to get rid of the year

 temdata = []
for i in data:
    temdata.append((i.split("=")[-1[])0:4])
name = list(set(temdata))
Copy the code

Then count the number of each year


temdict={}
for i in name:
    temdict[i]=temdata.count(i)
value_sorted_result = sorted(temdict.items(), key=lambda item: item[1], reverse=True)  # Descending by value
names = [i[0] for i in value_sorted_result]
value = [i[1] for i in value_sorted_result]
Copy the code

6 summary

This article explains how to climb PC data (take a cool video as an example, climb personal playback historical data, and visual display), the process is very detailed, full dry goods, hope can play a brick to introduce the effect, let everyone learn more technology!

If you think there is any other Angle to analyze the presentation data, please leave a comment below (I will read it carefully).