Why I write this article is mainly because I read an article.
The article describes an engineer who used Python+ADB+ GOOSE factory AI to watch more than 1,000 beautiful girls in one night.
Fully reflects the factory students and workers of the different, here I have to say a ××× cowhide…
Once I was alone in that big factory thinking about life, thinking about where I should go.
I remember that I also relied on douyin brush, through the difficult days.
Just not as strong as the big guy above, I am the artificial identification of beautiful little sister…
Even now I have registered the AI account of goose factory, but I still can’t use it.
So let’s start with something simple, pay attention to it in advance, and then use Python to automatically download street shooting videos!!
/ 01 / Charles
Charles is used to find the API interface of the video, and the specific operation is the same as the case of Dangdang before, without going into details.
Here, you can swipe douyin App to get the request information of the video.
Through many experiments, it was found that the back of the link would change constantly, but the front of the link remained unchanged, that is, “http://v1-dy”, “http://v6-dy” and “http://v9-dy”.
So when writing scripts, you can start with this information as a link.
/ 02 / mitmproxy
Mitmdump component in MitmProxy is used to connect with Python script, and Python is used to realize the processing after monitoring.
Here I’m just using the script to get the link, not directly using the script to download the video.
Because I’m running the script in the mitmdump.exe folder, I can’t import the Requests module from the script.
Don’t want to mess with those annoying environment variables, so just get the links.
Then go to download the video, the video link needs to be removed, there may be repeated.
The Python script is as follows.
def response(flow): Urls = [' http://v1-dy ', 'http://v3-dy', 'http://v6-dy', 'http://v9-dy'] # url filtering, only select video url for url in urls: Request. Url: print(' douyn.csv ') with open(' douyn.csv ', 'a+', encoding=' utF-8-sig ') as f: f.write(flow.request.url + ' ')Copy the code
/ 03 / Appium
Set the Appium parameter of Tiktok.
Click the blue button, the phone will automatically start douyin App!
Next, tap the phone and hit the Refresh button on Appium to get the element location code.
Through this practice, it is found that Appium sometimes does not get the location of elements well, which may be the same as iframe pages on the Web side.
So for elements I couldn’t find, I just clicked on the phone’s screen location.
Due to the different screen sizes of mobile phones, this parameter is bound to change, so there are drawbacks and cannot be used universally.
{swipe left and right to switch pictures}
The general operation is shown in the figure above. The UP main page is missing, please imagine, the Python code is as follows.
import time import random from appium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from appium.webdriver.common.touch_action import TouchAction from selenium.webdriver.support import expected_conditions as EC def main(): # set the drive configuration server = 'http://localhost:4723/wd/hub' desired_caps = {' platformName ':' Android ', 'deviceName: 'STF_AL00', 'appPackage': 'com.ss.android.ugc. Aweme ', 'appActivity': '.main.mainActivity ', # Turn off mobile phone soft keyboard 'unicodeKeyboard': True, 'resetKeyboard': True } driver = webdriver.Remote(server, desired_caps) wait = WebDriverWait(driver, 60) # Agree to user privacy agreement, click button_1 = wait. Until (ec.presence_of_element_located ((by.id, 'com. Ss. Android. Ugc. Aweme: id/q6'))) button_1. Click (#) prohibit telephone access, click button_2 = wait.until(EC.presence_of_element_located((By.ID, 'com. Android. Packageinstaller: id/permission_deny_button'))) button_2. Click () # location permissions, click button_3 = wait.until(EC.presence_of_element_located((By.ID, 'com. Android. Packageinstaller: id/permission_deny_button'))) button_3. Click () time. Sleep (# 2) sliding upwards and into shaking, audio and video page TouchAction(driver).press(x=515, y=1200).move_to(x=515, Y =1000).release().perform() # perform() # perform() # perform() # perform() # TouchAction(driver).press(x=950, Y =800).release().perform() # click button_4 = wait. Until (ec.presence_of_element_located ((by.id, 'com. Ss. Android. Ugc. Aweme: id/afg'))) button_4. Click () input account button_5 = # wait.until(EC.presence_of_element_located((By.ID, 'com. Ss. Android. Ugc. Aweme: id/ab_'))) button_5. Send_keys (' your account ') # input password button_6 = wait.until(EC.presence_of_element_located((By.ID, 'com. Ss. Android. Ugc. Aweme: id/aes'))) button_6. Send_keys (' your password) time. Sleep (# 2) will jump out of the soft keyboard because it is over, can cancel the login button, click cancel soft keyboard TouchAction(driver).press(x=980, Y =1).release().perform() time.sleep(2) # click button button_7 = wait. (ec.presence_of_element_located ((by.id, 'com. Ss. Android. Ugc. Aweme: id/abb'))) button_7. Click () time. Sleep (# 2) login successful, into shaking audio and video interface, click on the title bar below "I" TouchAction(driver).press(x=990, Y =1).release().perform() button_8 = wait. (ec.presence_of_element_located ((by.id, 'com. Ss. Android. Ugc. Aweme: id/a_7'))) button_8. Click (#) into the focus bar, click the second concern button_9 = wait.until(EC.presence_of_element_located((By.XPATH, ' /hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayo ut/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.LinearLayout/android.sup port.v7.widget.RecyclerView/android.widget.RelativeLayout[2]/android.widget.RelativeLayout[1]'))) button_9.click() # Button_10 = wait. Until (ec.presence_of_element_located ((by.id, 'com. Ss. Android. Ugc. Aweme: id/aqm'))) button_10. Click () # declining page, until the bottom while True: TouchAction(driver).press(x=515, y=1247).move_to(x=515, y=1026).release().perform() time.sleep(float(random.randint(5, 10))) if __name__ == '__main__': main()Copy the code
Download video code, need to video link to heavy.
import pandas as pd import requests import os num = 0 dom = [] folder_path = "F:/video/" os.makedirs(folder_path) df = Pd.read_csv ('douyin.csv', header=None, names=["url"]) Dom. Append (I) # for j in dom: url = j num += 1 response = requests.get(url, stream=True) filename = str(num) + '.mp4' with open('F:\video\' + filename, 'ab+') as f: F.lush (response.content) f.lush () print(filename + 'Download done ')Copy the code
Finally successfully get all the video of the girls…
If I had been in the factory, then this SAO operation should be much better, ha ha.
I was thinking more, most girls like douyin, but they probably won’t download it.
So little brother’s chance to come, download down like the girl’s douyin video.
Then I will edit a video series called “The Most Beautiful Moments”.
/ 04 / Summary
It’s all on GitHub. Github.com/Tobby-star/…
Click on the blue fontReceive thirty premium ebooks as a gift!