2014-01-23 97 views
0

所以我看着网页上的地方有一个播放列表中的视频。播放列表的问题是它不能“自动播放”。所以每当一个视频结束时,我必须手动进入播放列表并点击“下一步”链接。浏览器自动执行任务

有什么办法来自动完成这个?像这样的东西:

1.go to this page 
2.select the active item in the list(which contains the video duration) 
3.extract the video duration from the active item and let the video play 
4.After video duration, ex: 4min, click on the next element of the list and let it play for the video duration... 
... 

我用python和jquery很舒适。使用谷歌浏览器控制台可以实现这一目标?或者我可以运行的任何外部脚本?我也看到了Imacros,但它记录了特定的itens,并且我需要动态/程序。就像查找活动选定项目的下一个元素一样。

先谢谢你们。

回答

1

您可以使用Selenium来自动化各种浏览器。

Python bindings对硒的PyPI - 你可以看到链接的页面上的代码的一些例子,例如:

  • 打开一个新的Firefox浏览器
  • 负载的雅虎主页
  • 搜索对于 “seleniumhq”
  • 关闭浏览器

from selenium import webdriver 
from selenium.webdriver.common.keys import Keys 

browser = webdriver.Firefox() 

browser.get('http://www.yahoo.com') 
assert 'Yahoo!' in browser.title 

elem = browser.find_element_by_name('p') # Find the search box 
elem.send_keys('seleniumhq' + Keys.RETURN) 

browser.quit() 
+0

感谢您的输入DNA。只是一个简单的问题: 是否有可能让代码保持4分钟(视频持续时间),然后点击下一个链接?谢谢 – user1765661

+0

你可以使用'time.sleep()'。另请参阅http://selenium-python.readthedocs.org/en/latest/waits.html,了解如何等待某些条件发生。 – DNA