基于白嫖 阿里云官方demo SCF给网页拍个照

@Ta 2020-04-25发布,2020-04-25修改 6644点击
https://1911504709953557.cn-hangzhou.fc.aliyuncs.com/2016-08-15/proxy/puppeteer-test/html2png/?url=https://www.aliyun.com/product/fc

url=你想要的网址

这个是我从demo里找到的,阿里云官方应该是忘记关了,可以白嫖,不用付钱,
7419aeafc425f70909beb20dc98c629597001.png
回复列表(7|隐藏机器人聊天)
  • @Ta / 2020-04-25 / /

    分享源码

    健健康康

  • @Ta / 2020-04-25 / /
    @罐子,源码还要自己搭建,我这个是在官方文档中发现的demo,一时半会儿官方不会取消的。
    并且,demo源码是python2.7

    这里 我之前做过 基于php 的拍照 https://hu60.cn/q.php/bbs.topic.90400.html
  • @Ta / 2020-04-26 / /

    @胡椒舰长,demo源码是python2.7
    发来可好。
    健健康康

  • @Ta / 2020-04-26 / /
    const setup = require('./lib/setup');
    const fs = require('fs');
    
    
    module.exports.initializer = function(context, callback) {
      console.log('initializing');
      callback(null, ''); 
    };
    
    module.exports.handler = (req, resp, context) => {
      // Get the URL of the web page that needs screenshots from the request parameters
      let url = req.queries['url'];
      // If there is no url in the request parameters, set the default URL
      if (!url) {
        url = 'https://www.aliyun.com/product/fc';
      }
      // Whether it's HTTP or HTTPS, all prefixes are http
      if (!url.startsWith('https://') && !url.startsWith('http://')) {
        url = 'http://' + url;
      }
      
      screenshot(url, context)
        .then(outputFile => {
          // Get screenshot successful return
          resp.setStatusCode(200);
          resp.setHeader('content-type', 'image/png');
          resp.send(fs.readFileSync(outputFile))
        })
        .catch(err => {
          // Get screenshot failed return
          resp.setStatusCode(500);
          resp.setHeader('content-type', 'text/plain');
    
          resp.send(err.message);
        });
    };
    
    // Get screenshot method
    async function screenshot(url, context) {
      // Open a new browser viewport
      let browser = await setup.getBrowser(context);
    
      const page = await browser.newPage();
      const outputFile = '/tmp/screenshot.png';
    
      let retry = 0;
      let success = false;
      
      // Try to read the screenshot less than 6 times
      do {
        try {
          console.log('goto', url);
          await page.goto(url);
          success = true;
        } catch(e) {
          console.log('error', e);
          retry++;
    
          if (retry >= 6) {
            throw e;
          }
        }
      } while(!success && retry < 6);
    
      // Set the path of the screenshot, whether it is full page or not, and type
      await page.screenshot({
        path: outputFile,
        fullPage: true,
        type: 'png'
      });
    
      return outputFile;
    };
    
    



    @罐子
  • @Ta / 2020-04-26 / /

    这个挺好能生成整个页面截图
    手机

  • @Ta / 2020-04-26 / /
    @童真再见,JS渲染还是有问题,我建议用  PHP的wkhtmltoImg,这个python版的 效果没wkhtmltoImg效果好,而且wkhtmltoImg可以直接生成pdf
  • @Ta / 2020-04-26 / /
    你要会python 这网页截图太简单
添加新回复
回复需要登录