简体   繁体   English

将内容保存到 chrome 扩展中的文件

[英]save content to file in chrome extension

I want to get to a web page, extract the information I need and then write it in a text file and download it.我想访问一个网页,提取我需要的信息,然后将其写入文本文件并下载。 I couldn't find a way to download or copy the text.我找不到下载或复制文本的方法。

I made an extension which can download text in the popup script, and has the text I need in the content script but how to I connect them both?我制作了一个可以在弹出脚本中下载文本的扩展程序,并且在内容脚本中有我需要的文本,但是如何将它们连接起来?

content script:内容脚本:

let wordsList = [];
let meaningList = [];
let words = document.querySelectorAll(".status-m > div.word, .status-n > div.word");
let meaning = document.querySelectorAll(".status-m > div.meaning, .status-n > div.meaning");

wordsList = [...words];
wordsList = wordsList.map(word => word.innerHTML)

meaningList = [...meaning];
meaningList = meaningList.map(word => word.innerHTML)

let obj = {}
for(let i = 0; i< wordsList.length; i++){
    obj[wordsList[i]] = meaningList[i]
}

console.log(obj)

popup script弹出脚本

$(function(){      
    $('.btn').click(function(){
        const blob = new Blob(['text to download'],
            { type: "text/plain; charset=utf-8" });
        saveAs(blob, "static.txt");
    })
})

may use Powerpage command line to scrape a web page.可以使用Powerpage命令行来抓取网页。 program can be downloaded at https://github.com/casualwriter/powerpage程序可以在https://github.com/casualwriter/powerpage下载

// crawl innerHTML to html
powerpage.exe /url={link-web-page} /save={local-file.html} /select=".status-m > div.word, .status-n > div.word"

// crawl innerText to html
powerpage.exe /url={link-web-page} /save={local-file.html} /select="@.status-m > div.word, .status-n > div.word"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM