简体   繁体   English

如何将PhantomJS添加到我的Chrome扩展程序中?

[英]How Can I Add PhantomJS to My Chrome Extension?

I need to scrape (public) HTML Data after the JavaScript on the page has loaded. 页面上的JavaScript加载后,我需要抓取(公共)HTML数据。 After doing some research, I found that PhantomJS can be useful in accomplishing this task. 在进行了一些研究之后,我发现PhantomJS在完成此任务方面很有用。 However, while I can add PhantomJS to my local computer, I don't know how to add it to my chrome extension. 但是,尽管我可以将PhantomJS添加到本地计算机,但是我不知道如何将其添加到chrome扩展程序中。 Does anybody know how I can accomplish this? 有人知道我该怎么做吗?

You cannot. 你不能。 PhantomJS is a web browser, not a Javascript library. PhantomJS是Web浏览器,而不是Javascript库。

Alternative 1. Scrape from the Chrome Extension 替代方法1.从Chrome扩展程序中抓取

You can use the chrome extension APIs to do the following: 您可以使用chrome扩展API进行以下操作:

  1. Create a tab containing the page you want to scrape 创建一个选项卡,其中包含您要抓取的页面
  2. Load a content script into the tab that: 将内容脚本加载到选项卡中:
    1. Waits for the page to finish loading 等待页面完成加载
    2. Scrapes the data you want 收集所需的数据
    3. Messages the scraped data to wherever you need it 将抓取的数据发送到您需要的任何地方
  3. Close the tab 关闭标签

Alternative 2. Scrape with a Headless Browser Running on Your Own Server 替代方案2.使用在自己的服务器上运行的无头浏览器进行抓取

Use Google's own headless Chrome library puppeteer to scrape the data you want. 使用Google自己的无头Chrome库木偶抓取所需的数据。 An easy way to get started for free is with a Google App Engine Standard Tier NodeJS instance . 一个免费的免费入门入门方法是使用Google App Engine标准层NodeJS实例

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

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