js获取抖音视频信息配合服务器自动下载

引入axios

方便发送请求

解析当前页面获取视频信息

把数据发送到服务器

注意端口号,1024以上浏览器可能会拦截,认为不安全
重复发送,防止连续重复发送,手动清除定时器

点击查看代码
 
// 导入axios.pos
let script = document.createElement('script');
script.src = "https://unpkg.com/axios/dist/axios.min.js";
document.getElementsByTagName('head')[0].appendChild(script);
 
class DySender {
  constructor() {
    this.old = null;
    this.interval = null;
  }

  getDyOne(info) {
    return info.length === 1 ? info[0] : info[1];
  }

  dyInfo() {
    const dy = {};
    dy.stat = document.querySelector('.OFZHdvpl').innerText;
    const info = this.getDyOne(document.querySelectorAll('.video-info-detail'));
    dy.id = info.dataset.e2eAwemeId;
    dy.desc = info.innerText;
    dy.src = this.getDyOne(document.querySelectorAll('video')).currentSrc;
    dy.reply = this.getDyOne(document.querySelectorAll('#videoSideBar')).innerText;
    dy.now = new Date().toLocaleString().replaceAll('/', '-');
    return dy;
  }

  sendDy() {
    const dy = this.dyInfo();
    if (this.old && this.old.id === dy.id) {
      return 'skip';
    }
    axios.post('http://localhost:600/receiver/movie', {
      url: window.location.href,
      data: dy,
    }).then(
      (res)=>{
        console.log(res.status)
        console.log('success '+dy.desc)
      }
    );
    this.old = dy;
  }

  startSending() {
    this.interval = setInterval(() => {
      this.sendDy();
    }, 1000);
  }

  stopSending() {
    clearInterval(this.interval);
  }
}

const dySender = new DySender();
dySender.startSending();

posted @ 2023-05-26 11:27  caiusxin  阅读(150)  评论(0编辑  收藏  举报
// 侧边栏目录 // https://blog-static.cnblogs.com/files/douzujun/marvin.nav.my1502.css