• 请不要在回答技术问题时复制粘贴 AI 生成的内容
standin000
V2EX  ›  程序员

请教有没有简单转换HTML邮件中的远程图片为本地图片的图片

  •  
  •   standin000 · Dec 18, 2013 · 3385 views
    This topic created in 4601 days ago, the information mentioned may be changed or developed.
    等于新生成一个HTML文件,即使离线时也能使用。

    最好是命令行或者Javascrip库。

    谢谢!
    3 replies    1970-01-01 08:00:00 +08:00
    loading
        1
    loading  
       Dec 18, 2013
    网页截图
    standin000
        2
    standin000  
    OP
       Dec 19, 2013
    @loading 截图就变成图片了,我想要HTML文件
    standin000
        3
    standin000  
    OP
       Dec 22, 2013
    var $ = require('jquery');
    var fs = require('fs');
    var request = require('request');

    var download = function(uri, filename){
    request.head(uri, function(err, res, body){
    request(uri).pipe(fs.createWriteStream(filename));
    });
    };

    fs.readFile('./1.html',function(err,data){
    if(err) throw err;
    HTML = data.toString();
    var new_html = $(HTML);
    var oldsrc,src;

    new_html.find('img').each(function(index,image){
    oldsrc = $(image).attr('src');
    src = oldsrc.replace(/^.*\//, './');
    download(oldsrc, src);
    $(image).attr('src', src);
    });

    console.log(new_html[0].innerHTML);
    });


    没有找到,自己搞定!
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2692 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 11:58 · PVG 19:58 · LAX 04:58 · JFK 07:58
    ♥ Do have faith in what you're doing.