Last active
June 3, 2023 09:54
-
-
Save tudoanh/feda12ff6f97ce5bf9a55c75845ce7ea to your computer and use it in GitHub Desktop.
Douyin get video url without watermark
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from selenium import webdriver | |
from selenium.webdriver.chrome.service import Service | |
from selenium.webdriver.support.ui import WebDriverWait | |
from selenium.webdriver.support import expected_conditions as EC | |
from webdriver_manager.chrome import ChromeDriverManager | |
from selenium.webdriver.common.by import By | |
def get_douyin_video(url): | |
options = webdriver.ChromeOptions() | |
chrome_options = { | |
'credentials_enable_service': False, | |
'profile.password_manager_enabled': False, | |
} | |
options.add_experimental_option('prefs', chrome_options) | |
# headless | |
options.add_argument("--headless") | |
driver = webdriver.Chrome( | |
options=options, service=Service(ChromeDriverManager().install()) | |
) | |
# Open the website | |
driver.get("https://douyin.wtf/") # Replace with the actual URL of the website | |
driver.implicitly_wait(3) # Adjust the wait time as per your needs | |
# Find the textarea and input the URL | |
url_textarea = WebDriverWait(driver, 10).until( | |
EC.visibility_of_element_located((By.CLASS_NAME, "form-control")) | |
) | |
url_textarea.send_keys(url) # Replace with the actual URL | |
# Click the submit button | |
submit_button = driver.find_element(by=By.XPATH, value="//button[@class='btn btn-primary']") | |
submit_button.click() | |
# Wait for the response to render (assuming it takes some time) | |
driver.implicitly_wait(3) # Adjust the wait time as per your needs | |
# Find the table rows | |
table_rows = WebDriverWait(driver, 10).until( | |
EC.visibility_of_all_elements_located((By.XPATH, "//table//tr")) | |
) | |
video_url = table_rows[5].find_element(by=By.XPATH, value=".//td[2]").find_element(by=By.XPATH, value=".//a").get_attribute("href") | |
# Close the browser | |
driver.quit() | |
return video_url |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the work :)