2016-04-08 17 views
0

thisサイトを使用して、YouTubeからMP3ファイルを自動ダウンロードしようとしています。セレン:ファイルをダウンロードできません

目的:

  • 訪問のダウンロードWebサイト
  • クリックして表示させるダウンロードリンク用
  • 待ち "のビデオを変換する" YouTubeのリンクを貼り付け、その後、

それをクリックしてくださいbrowser.find_by_id('dl_link').click()を使用すると、私のコードexecuファイルはダウンロードされません。どうして?

browser.click_link_by_partial_text( 'ダウンロード')を使用すると、次のエラーが表示されます。ここで

は私のコードです:私はすでに同じ(エラーと他の質問をチェックした

Traceback (most recent call last): 
    File "/Users/anon/Dropbox/Programs/Proj/splinter2.py", line 11, in <module> 
    browser.click_link_by_partial_text('Download') 
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/splinter/driver/__init__.py", line 332, in click_link_by_partial_text 
    return self.find_link_by_partial_text(partial_text).first.click() 
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/splinter/driver/webdriver/__init__.py", line 539, in click 
    self._element.click() 
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/remote/webelement.py", line 74, in click 
    self._execute(Command.CLICK_ELEMENT) 
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/remote/webelement.py", line 457, in _execute 
    return self._parent.execute(command, params) 
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 233, in execute 
    self.error_handler.check_response(response) 
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response 
    raise exception_class(message, screen, stacktrace) 
selenium.common.exceptions.ElementNotVisibleException: Message: Element is not currently visible and so may not be interacted with 
Stacktrace: 
    at fxdriver.preconditions.visible (file:///var/folders/wj/t56fgsms4rdcgptcy94k2w8m0000gn/T/tmpAVUrd2/extensions/[email protected]/components/command-processor.js:10092) 
    at DelayedCommand.prototype.checkPreconditions_ (file:///var/folders/wj/t56fgsms4rdcgptcy94k2w8m0000gn/T/tmpAVUrd2/extensions/[email protected]/components/command-processor.js:12644) 
    at DelayedCommand.prototype.executeInternal_/h (file:///var/folders/wj/t56fgsms4rdcgptcy94k2w8m0000gn/T/tmpAVUrd2/extensions/[email protected]/components/command-processor.js:12661) 
    at DelayedCommand.prototype.executeInternal_ (file:///var/folders/wj/t56fgsms4rdcgptcy94k2w8m0000gn/T/tmpAVUrd2/extensions/[email protected]/components/command-processor.js:12666) 
    at DelayedCommand.prototype.execute/< (file:///var/folders/wj/t56fgsms4rdcgptcy94k2w8m0000gn/T/tmpAVUrd2/extensions/[email protected]/components/command-processor.js:12608) 
[Finished in 7.2s with exit code 1] 
[shell_cmd: python -u "/Users/anon/Dropbox/Programs/Proj/splinter2.py"] 
[dir: /Users/anon/Dropbox/Programs/Proj] 
[path: /usr/bin:/bin:/usr/sbin:/sbin] 

を:ここで

from splinter.browser import Browser 
import time 

with Browser() as browser: 
    browser.visit("http://www.youtube-mp3.org") 
    browser.find_by_id('youtube-url').fill("https://www.youtube.com/watch?v=lgT1AidzRWM") 
    browser.find_by_id('submit').click() 

    if browser.is_element_present_by_id('dl_link'): 
     time.sleep(2) 
     browser.click_link_by_partial_text('Download') 
     # browser.find_by_id('dl_link').click() 
     print "Clicked Download" 
     time.sleep(2) 

は私が取得していますエラーです「要素が現在表示されていないと私の場合はDownloadボタンが表示されているので、これを解決することはできません。

任意の助けもいただければ幸いです

EDIT:

私はbrowser = Browser('firefox', profile=profile)を使用してプロファイルを設定しようとするたびに、私は次のエラーを取得:

Traceback (most recent call last): 
    File "/Users/adb/Dropbox/Programs/Proj/Youtube Playlist MP3/splinter2.py", line 11, in <module> 
    browser = Browser('firefox', profile=profile) 
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/splinter/browser.py", line 63, in Browser 
    return driver(*args, **kwargs) 
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/splinter/driver/webdriver/firefox.py", line 23, in __init__ 
    firefox_profile = FirefoxProfile(profile) 
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/firefox/firefox_profile.py", line 77, in __init__ 
    ignore=shutil.ignore_patterns("parent.lock", "lock", ".parentlock")) 
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 171, in copytree 
    names = os.listdir(src) 
TypeError: coercing to Unicode: need string or buffer, FirefoxProfile found 
+2

ブラウザのダウンロードフォルダがありません。これは、ブラウザプロファイルを設定することで行われます。https://github.com/cobrateam/splinter/blob/master/splinter/driver/webdriver/firefox.py#L25 – sousatg

+0

http:// stackoverflow。com/questions/18439851/downloading-file-using-selenium –

+0

@sousatgブラウザプロファイルを設定しようとしましたが、編集でエラーが表示され続けます – WhiteFlameAB

答えて

0
  1. をbrowser.find_by_id( 'dl_link').Click()を使用すると、コードがnyエラーですが、browser.click_link_by_partial_text( 'Download')はスローされますか?

あなたは "静的" 要素と相互に作用するので。

「ビデオを変換」ボタンを押すと、DOMが更新されます。しかし、あなたのドライバは古いDOMで動作します。だからこそあなたが見つけられない理由は、browser.click_link_by_partial_text('Download')

  1. このファイルがダウンロードされていないと、ダウンロードされません。どうして?

は、おそらくあなたが保存してそれを実行するかどうかを尋ねるポップアップウィンドウがありますので。 Check this out

関連する問題