js获取抖音弹幕
使用JS 注入 注入方式 是以浏览器插件
function dom() {
// 创建一个MutationObserver实例
let mutationObserver = new MutationObserver(function(mutationsList, observer) {
for(var mutation of mutationsList) {
console.log("用户:",mutation.target.lastChild.lastChild.childNodes[1].textContent,'信息:', mutation.target.lastChild.lastChild.lastChild.textContent);
}
});
// 选择要监视的DOM元素,这里假设是抖音Web端的弹幕容器
let targetElement = document.querySelector("#_douyin_live_scroll_container_ > div > div > .Iy_uuM55 > .__playerIsFullChatroom > .ro3xcipQ > .lF9JOwdS > div > .webcast-chatroom___messages > div > .webcast-chatroom___item-offset > div > div:nth-child(1)");
if(targetElement){
// 启动观察器,开始监视目标元素的变化
mutationObserver.observe(targetElement, { attributes: true, childList: true });
}else{
console.log('Target element not found');
}
}
本文来自博客园,作者:樱桃树下的约定,转载请注明原文链接:https://www.cnblogs.com/tcyweb/p/17836249.html