V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
r1nging
V2EX  ›  Python

Python 如何控制网页播放器的进度

  •  
  •   r1nging · 2017-09-05 09:25:34 +08:00 · 3401 次点击
    这是一个创建于 2433 天前的主题,其中的信息可能已经有所发展或是发生改变。
    比如说爱奇艺的进度条,让它快进 10 分钟。。。
    第 1 条附言  ·  2017-09-07 07:51:58 +08:00
    折腾了几天终于解决了

    selenium 有个 ActionChains 方法

    from selenium.webdriver.common.action_chains import ActionChains

    找到进度条的按钮就行了。。。

    ActionChains(browser).click_and_hold(brightnessSlider).move_by_offset(300,0).release().perform()

    其实这个办法还可以控制滑块验证
    第 2 条附言  ·  2017-09-07 07:53:27 +08:00
    还是要感谢 ma6254 和 debuggerx 提供的思路。
    4 条回复    2017-09-05 12:44:18 +08:00
    ma6254
        1
    ma6254  
       2017-09-05 10:06:34 +08:00   ❤️ 1
    可以用 selenium 这个库,他里面有个 executeScript 函数,可以用来执行 js
    http://selenium-python.readthedocs.io/api.html
    然后 js 有函数可以用来控制<video>,play 和 pause 用来开始和暂停,currentTime 用来控制播放时间
    https://msdn.microsoft.com/zh-cn/library/hh924823(v=vs.85).aspx
    ma6254
        2
    ma6254  
       2017-09-05 10:10:05 +08:00   ❤️ 1
    debuggerx
        3
    debuggerx  
       2017-09-05 10:22:27 +08:00   ❤️ 1
    javascript:document.getElementsByTagName('video')[0].currentTime = document.getElementsByTagName('video')[0].currentTime + 600;

    直接在浏览器地址栏粘贴回车就能测试了

    奇怪的是实测 b 站是有效果的,iqiyi 只是停了一小会然后继续从之前的分段继续播放了……
    r1nging
        4
    r1nging  
    OP
       2017-09-05 12:44:18 +08:00
    有了 selenium 那现在的问题就是 Javascript 如何控制网页播放器的进度。。。。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2479 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 12:24 · PVG 20:24 · LAX 05:24 · JFK 08:24
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.