斗鱼自动发弹幕

斗鱼自动发弹幕

斗鱼自动发弹幕,复制到控制台运行即可
(function () {
      var _timer_ = null;
      var spred = ['.', '.', '.', '.', '.'];
      var start = 1;
      // 加载样式
      var fixInp = document.createElement('textarea');
      var fixSend = document.createElement('input');
      var fixStop = document.createElement('input');
      var tips1 = document.createElement('p');
      var tips2 = document.createElement('span');
      var times = document.createElement('input');
      var fixWrap = document.createElement('div');
      var outer = document.createElement('div');
      var hide = document.createElement('span');
      var show = document.createElement('span');
      var checkdiv = document.createElement('div');
      var checkTip = document.createElement('span');
      var check = document.createElement('input');
      fixSend.setAttribute('type', 'submit');
      fixSend.setAttribute('value', '发送');
      fixStop.setAttribute('type', 'submit');
      fixStop.setAttribute('value', '停止');
      times.setAttribute('type', 'number');
      check.setAttribute('type', 'checkbox');
      tips1.innerHTML = '内容:';
      tips2.innerHTML = '间隔(秒):';
      hide.innerHTML = '隐藏';
      show.innerHTML = '显示';
      checkTip.innerHTML = '防重复发言:';
      outer.style.cssText = 'position: fixed; right: 10px; bottom: 10px; display: block; width:200px;padding: 10px; background:#4CAF50;z-index: 9999999;';
      times.style.cssText = 'display: inline-block; width: 40px;';
      fixInp.style.cssText = 'display: block;width: 100%;height:62px;box-sizing: border-box;';
      tips1.style.cssText = 'margin:0;padding:0;';
      fixWrap.style.cssText = 'display: inline-block;width:100%;';
      show.style.cssText = 'position: fixed; right: 10px; bottom: 10px;display:none;padding:2px; background:#4CAF50;font-size: 12px;color: #fff; cursor: pointer;';
      hide.style.cssText = 'display:inline-block;padding:2px; background:#b22;font-size: 12px;color: #fff; cursor: pointer;';
      times.value = 10;
      fixWrap.appendChild(hide);
      fixWrap.appendChild(tips1);
      fixWrap.appendChild(fixInp);
      fixWrap.appendChild(tips2);
      fixWrap.appendChild(times);
      fixWrap.appendChild(fixSend);
      fixWrap.appendChild(fixStop);
      checkdiv.appendChild(checkTip);
      checkdiv.appendChild(check);
      fixWrap.appendChild(checkdiv);
      outer.appendChild(fixWrap);
      document.body.appendChild(outer);
      document.body.appendChild(show);
      // 发送弹幕
      function send(message, bool) {
        if (bool) {
          var s = spred.slice(0, start++);
          message += s.join('');
          if (start > spred.length) {
            start = 1
          }
        }
        document.querySelector('.ChatSend-txt').value = message;
        document.querySelector('.ChatSend-button').click();
      }
      // 事件
      fixSend.addEventListener('click', function () {
        var time = parseInt(times.value);
        var message = fixInp.value;
        var bool = check.checked;
        fixSend.style.display = 'none';
        send(message);
        _timer_ = setInterval(function () {
          send(message, bool);
        }, time * 1000);
      });
      fixStop.addEventListener('click', function () {
        fixSend.style.display = 'inline-block';
        clearInterval(_timer_);
        _timer_ = null;
      });
      hide.addEventListener('click', function () {
        outer.style.display = 'none';
        show.style.display = 'inline-block';
      });
      show.addEventListener('click', function () {
        outer.style.display = 'block';
        show.style.display = 'none';
      });
    })();

在这里插入图片描述

  • 13
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 9
    评论
Python 斗鱼自动弹幕可以通过使用第三方库来实现,比如使用 Selenium 和 ChromeDriver。 首先,需要安装 Selenium 和 ChromeDriver。可以通过 pip 命令来安装 Selenium,通过下载 ChromeDriver 并将其路径添加到系统环境变量中。 接下来,我们可以编写 Python 脚本来实现自动弹幕的功能。 首先,导入 Selenium 和 需要的模块: ```python from selenium import webdriver from selenium.webdriver.common.keys import Keys import time ``` 然后,创建 ChromeDriver 的实例,并打开斗鱼网站: ```python driver = webdriver.Chrome() driver.get("https://www.douyu.com/") time.sleep(3) ``` 接下来,我们可以通过定位网页元素的方式,找到弹幕的文本框,并输入要送的内容: ```python text_box = driver.find_element_by_class_name("ChatSend-txt") text_box.send_keys("要送的弹幕内容") time.sleep(1) ``` 然后,通过定位送按钮,并模拟点击: ```python send_button = driver.find_element_by_class_name("ChatSend-button") send_button.click() time.sleep(1) ``` 最后,关闭 ChromeDriver: ```python driver.quit() ``` 完整代码如下: ```python from selenium import webdriver from selenium.webdriver.common.keys import Keys import time driver = webdriver.Chrome() driver.get("https://www.douyu.com/") time.sleep(3) text_box = driver.find_element_by_class_name("ChatSend-txt") text_box.send_keys("要送的弹幕内容") time.sleep(1) send_button = driver.find_element_by_class_name("ChatSend-button") send_button.click() time.sleep(1) driver.quit() ``` 以上就是使用 Python 实现斗鱼自动弹幕的方法。可以根据实际需求进行修改和扩展。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值