I am using selenium library for python and chrome browser.
I need to click a link from the url:
http://www.youtube-mp3.org/
The idea is to download a list of videos converted to mp3 files in a previous code. My script is:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
url2='http://www.youtube-mp3.org/'
chromedriver = 'C:\\exp\\chromedriver.exe' #where you have the file
browser = webdriver.Chrome(chromedriver)
browser.get(url2)
direc = browser.find_element_by_id("youtube-url")
direc.clear()
direc.send_keys("https://www.youtube.com/watch?v=nYh-n7EOtMA") #an example url
browser.find_element_by_id("btns").click()
Until here everything is ok.
Now I need to press the download link that appears after the video is converted.
The html for that part is:
<div id="dl_link" style="display: block;">
<a href="/get?video_id=nYh-n7EOtMA&h=-1&r=-1.1" style="display:none"><b>Download</b></a>
<a href="/get?video_id=nYh-n7EOtMA&ts_create=1463533555&r=MTg2LjYwLjE2MS4yMTE%3D&h2=5ad90182ae65fea567f844c3b6a933aa&s=145334"><b>Download</b></a><a href="/get?video_id=nYh-n7EOtMA&h=-1&r=-1.1" style="display:none">
<b>Download</b>
</a></div>
But I can only see it when I select "inspect object", because if I select "view source code" (after I pasted the url and the video and link appear), there's nothing in it.
I tried with:
browser.find_element_by_partial_link_text("create").click()
But I got an error:
NoSuchElementException: Message: no such element
and also with:
browser.find_element_by_name("dl_link").click()
error:
NoSuchElementException: Message: no such element: Unable to locate element: {"method":"name","selector":"dl_link"}
and also with:
browser.find_element_by_id("dl_link").click()
and got:
ElementNotVisibleException: Message: element not visible
So, my questions are:
- why I cannot see the html script for the download link when I press view source code?
- is it possible to finish the process (downloading the mp3 file) with python?
- does the fact that the web page has java scripts in it is related to the issue?
- is there any other library to do this?
thanks.
browser.find_element_by_name("dl_link").click()shall work ideally.