electron获取第三方网站的dom

最近公司有个需求,通过electron引入的第三方网站,打开时,要能自动登录进行页面跳转,于是在研究了一翻...

1.通过webviwe引入第三方网站

<webview id="wb" src="https://www.baidu.com/"  preload="./render/test.js"
    style="width:100%; height:calc(100vh - 0px)"></webview>

2.preload里执行dom的获取等相关操作

let handle = setInterval(() => {
  if (document.querySelector('.login-form')){
    clearInterval(handle);
    let form = document.getElementsByClassName('login-form')[0]
    let inps = form.getElementsByTagName('input')
    inps[0].value = ''
    inps[1].value = ''

   // Js修改input值后怎么同步修改绑定的v-model值
    inps[0].dispatchEvent(new Event("input")) 
    inps[1].dispatchEvent(new Event("input"))

    let btn = form.getElementsByClassName('login-btn')[0]
    btn.click()
  }else{
    console.log('error');
  }
}, 200);

 

posted @ 2022-09-06 18:01  cmwang2017  阅读(458)  评论(0编辑  收藏  举报