Home > Software engineering >  QUICK EASY: How do I print the link for the mp4 in this page?
QUICK EASY: How do I print the link for the mp4 in this page?

Time:05-03

I am trying to navigate to the following page and print the link that ends in .mp4.

I can see the link under Chrome's Inspect > Network but I can't print.

https://www.learningcontainer.com/mp4-sample-video-files-download/

Desired link to be printed:

https://www.learningcontainer.com/wp-content/uploads/2020/05/sample-mp4-file.mp4

Code attempt:

from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://www.learningcontainer.com/mp4-sample-video-files-download/")
driver.find_element_by_css_selector(".elementor-video").click()
print(???)

PLEASE HELP.

CodePudding user response:

Steps :

  1. get the list of all links in the web page, use find_elements_by_tag_name("a")
  2. use get_attribute('href') for every link you found in the page.
  3. for every href value check if it ends with .MP4

full code :

myLinks = find_elements_by_tag_name("a")
for mp4Link in myLinks :
    if (mp4Link.get_attribute("href").endswith(".mp4")) print (mp4Link .get_attribute("href"))

CodePudding user response:

elem=driver.find_element(BY.CSS_SELECTOR,".elementor-video")
print(elem.get_attribute('src'))

Just print out the src attribute.

  • Related