Web Scraping in a Google Chrome Extension (JavaScript + Chrome APIs)

后端 未结 7 959
独厮守ぢ
独厮守ぢ 2020-12-12 09:31

What are the best options for performing Web Scraping of a not currently open tab from within a Google Chrome Extension with JavaScript and whatever more te

7条回答
  •  不思量自难忘°
    2020-12-12 10:24

    Web scraping is kind of convoluted in a Chrome Extension. Some points:

    • You run content scripts for access to the DOM.
    • Background pages (one per browser) can send and receive messages to content scripts. That is, you can run a content script that sets up an RPC endpoint and fires a specified callback in the context of the background page as a response.
    • You can execute content scripts in all frames of a webpage, then stitch the document tree (composed of the 1..N frames that the page contains) together.
    • As S.K. suggested, your background page can send the data as an XMLHttpRequest to some kind of lightweight HTTP server that listens locally.

提交回复
热议问题