File size: 2,142 Bytes
9e7c01a ef788d8 ce1f885 ef788d8 472154b 9e7c01a 10e999f ef788d8 9e7c01a 10e999f 9e7c01a 10e999f 9e7c01a 5370707 7d9bc27 5370707 7d9bc27 5370707 10e999f 5370707 10e999f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
from selenium import webdriver
from selenium.common.exceptions import WebDriverException
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
# Initialize the Chrome WebDriver
driver = webdriver.Chrome(options=options)
# Go to the provided URL
url = "https://genyoutube.online/url=https://www.youtube.com/watch?v=-2RAq5o5pwc&list=RD-2RAq5o5pwc&start_radio=1"
driver.get(url)
# Print the page title to verify success
print(driver.title)
jsc = """
function find360pLink() {
// Select all table rows
const rows = document.querySelectorAll('tr');
let link = '';
// Loop through each row to find the one containing "360p"
rows.forEach(row => {
const cells = row.getElementsByTagName('td');
if (cells.length > 0 && cells[0].textContent.includes("360p")) {
// Find the anchor element within this row
const anchor = row.querySelector('a');
if (anchor) {
link = anchor.getAttribute('href'); // Get the href attribute
}
}
});
// Print the link
if (link) {
console.log('360p Link:', link);
return link
} else {
console.log('360p link not found.');
}
}
// Call the function to find the 360p link
return find360pLink();
"""
dls = driver.execute_script(jsc)
print(dls)
# Use WebDriverWait to wait for the element to be present
#try:
# my_tab_content = WebDriverWait(driver, 10).until(
# EC.presence_of_element_located((By.ID, "myTabContent"))
# )
# print(my_tab_content.text) # Print the text content
#except Exception as e:
# print("Error locating the element:", e)
# Close the browser session
driver.quit()
|