浏览器自动执行任务

时间:2014-01-23 15:50:51

标签: jquery python google-chrome

所以我正在网页上看一些有播放列表的视频。播放列表的问题在于它不会“自动播放”。因此,每当一个视频结束时,我必须手动转到播放列表并单击“下一个”链接。

有没有办法实现自动化?类似的东西:

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。使用谷歌Chrome控制台有可能实现这一目标吗?或者我可以运行的任何外部脚本?我也见过Imacros,但它记录了特定的itens,我需要一些动态/程序性的东西。就像找到活动所选项目的下一个元素一样。

先谢谢你们。

1 个答案:

答案 0 :(得分:1)

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

PyPI中有Python bindings个Selenium - 您可以在链接页面上看到一些代码示例,例如:

  • 打开一个新的Firefox浏览器
  • 加载Yahoo主页
  • 搜索“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()