如何使用phantomjs或其他浏览器在nodejs中创建Web代理?

问题描述 投票:2回答:1

我一直在尝试使用phanthonjs或类似的方法创建一个Web代理服务器,并在浏览器中查看和导航

var phantom = require('phantom');

phantom.create().then(function(ph) {
  ph.createPage().then(function(page) {
    page.open('https://stackoverflow.com/').then(function(status) {
      console.log(status);
      page.property('content').then(function(content) {
        console.log(content);
        page.close();
        ph.exit();
      });
    });
  });
});
node.js proxy phantomjs
1个回答
1
投票
const express = require('request');
const puppeteer = require('puppeteer');

const app = express();

app.use('/', async (req, res) => {
   const url = 'http://somesite.com';
   const browser = await puppeteer.launch();
   const page = await browser.newPage();
   await page.goto(url);
   const content = await page.content();
   res.send(content);
   await browser.close();
});

app.listen(3000, () => { console.log('App is running on port 3000') }

多数民众赞成我将如何实现它,如果我想使用无头浏览器。语法与其他无头浏览器不同。但是想法是完全一样的。 :)

© www.soinside.com 2019 - 2024. All rights reserved.