Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to monitor Douyin online time by Python

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to achieve Python monitoring Douyin online time, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor with you to understand.

As shown below:

Just enter the Douyin message box, and then enter the user chat window, you can see the above online status.

Then I had an idea, can I use python to monitor a person's online situation throughout the day in real time?

Just do it and decide to operate on my roommate first.

1. Logical analysis

As the saying goes, sharpen a knife without mistakenly chopping firewood, and you must analyze the logic clearly before doing anything, otherwise you will only get half the result with twice the effort.

At first, I wanted to use the mobile phone simulator to operate, but unfortunately, the mobile phone simulator did not show the online status, so I had no choice but to contribute my beloved mobile phone.

First, open Douyin with the appium client (for the installation and use of appium, please refer to the previous article). The configuration is shown in the figure:

Click the message element:

Click again to enter the chat window:

The id that displays the presence element is:

Com.ss.android.ugc.aweme:id/blc

In that case, we only need to keep asking for the value of the element on the current page to get the friend's online status, and if we return "online", the user will be judged to be online; otherwise, it will be judged not to be online.

The 2.Python code will be pulled up.

1.appium module controls to open Douyin

Desired_caps = {"platformName": "Android", "deviceName": "MHA_AL00", "appPackage": "com.ss.android.ugc.aweme", "appActivity": ".main.MainActivity", "noReset": "true" "fullReset": "false"} server = 'http://localhost:4723/wd/hub'driver = webdriver.Remote (server, desired_caps)

two。 Click to enter the message list and the user chat window.

Driver.find_element_by_xpath ('/ / android.widget.TextView [contains (@ text, "message")]') .click () time.sleep (1) driver.find_element_by_xpath ('/ / android.widget.TextView [contains (@ text, "Goddess's nickname")]') .click ()

3. Get online status and time and save

While True: status=driver.find_element_by_id ('com.ss.android.ugc.aweme:id/blc'). Text strtime = time.strftime ("% H:%M:%S" Time.localtime (time.time ()) if status==' online': status=' online 'else: status=' not online' wb = xlrd.open_workbook ('1.xls') tabsheet = wb.sheets () [0] k = number of rows in tabsheet.nrows # form worksheet.write (k, 0, I [' name']) # Hotel name worksheet.write (k, 1 I ['addr']) # Hotel address time.sleep (60)

4. Draw a line chart according to the online status

Df = pd.read_excel ('1.xlsgiving, encoding='gbk', usecols= [' time', 'status']) line = Line ("line chart") line.add ("presence", df ['time'], df ['status'], xaxis_rotate=45) line.render ('line chart .html')

According to the living habits of contemporary "smelly" youth, nine times out of ten they are browsing Douyin before and after waking up, so it can be inferred that the roommate woke up around 09:20 and slept around 23:00 today, and he still seems to have a regular schedule.

Thank you for reading this article carefully. I hope the article "how to monitor Douyin online time by Python" shared by the editor will be helpful to everyone. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you 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: 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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report