You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
python/文档/百度文库下载脚本.txt

26 lines
747 B

//1.获取文本
let topDiff = -1;
let content = "";
var filename= document.getElementsByClassName('doc-title')[0].innerText;
const target = document.querySelectorAll(".reader-word-layer");
target.forEach(x => {
if (x.style.top !== topDiff) {
content += "\n";
topDiff = x.style.top;
};
content += x.innerText;
});
//2.创建下载链接,下载到本地
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(content));
element.setAttribute('download', filename+".doc");
element.style.display = ".reader-word-layer";
document.body.appendChild(element);
element.click();
document.body.removeChild(element);