iframe 绕过 微信公众号文章防盗检测

多说无益 贴一段使用的代码

getUrl(URL){
//url 为微信公众号文章链接
     let http = (window.location.protocol === 'http:' ? 'http:' : 'https:');
     let realurl = http + '//cors-anywhere.herokuapp.com/' + URL;
     axios.get(realurl).then((response)=>{
       console.log(response)
       let html = response.data;
       html = html.replace(/data-src/g, "src")
                  .replace(/)<[^<]*)*<\/script>/g, '')
                  .replace(/https/g,'http');
       let html_src = 'data:text/html;charset=utf-8,' + html;
       let iframe = document.getElementById('iFrame');
       iframe.src = html_src;
     },(err)=>{console.log(err);});

总结
1 用ajax请求公众号文章链接
2 js 字符串方法替换 其中 src script http 等字段
3 重新设置 html 头部
4 动态创建 iframe 标签

你可能感兴趣的:(微信)