简体   繁体   English

浏览器自动执行任务

[英]Browser automate tasks

So I am watching some videos on a webpage where there is a playlist. 因此,我正在一个有播放列表的网页上观看一些视频。 The problem with the playlist is that it doesnt "auto-play". 播放列表的问题在于它不会“自动播放”。 SO everytime one video ends I have to manually go to the playlist and click on the "next" link. 因此,每当一个视频结束时,我都必须手动转到播放列表,然后单击“下一个”链接。

Is there any way to automate this? 有什么办法可以自动化吗? SOmething like: 就像是:

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...
...

I am confortable with python and jquery. 我对python和jquery感到满意。 using the google chrome console is possible to achive this? 使用谷歌浏览器控制台可以实现这一目标? Or any external script that I can run? 还是我可以运行的任何外部脚本? I have also seen Imacros but it records specific itens, and I need something dynamic/procedual. 我也看过Imacros,但它记录了特定的Iten,并且我需要动态/过程的东西。 Like find the next element of the active selected item. 就像查找活动所选项目的下一个元素。

Thank you in advance guys. 预先谢谢你们。

You can use Selenium to automate a variety of browsers. 您可以使用Selenium来自动化各种浏览器。

There are Python bindings for Selenium in PyPI - you can see some examples of the code on the linked page, for example: PyPI中有Selenium的Python绑定 -您可以在链接的页面上看到一些代码示例,例如:

  • open a new Firefox browser 打开一个新的Firefox浏览器
  • load the Yahoo homepage 加载Yahoo主页
  • search for "seleniumhq" 搜索“ seleniumhq”
  • close the browser 关闭浏览器

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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM