【问题标题】:How to export/extract google satellite map to the images automatically?如何自动将谷歌卫星地图导出/提取到图像?
【发布时间】:2014-12-31 12:35:55
【问题描述】:

我需要使用几张google航拍图进行图像处理,因为我需要很多图片,所以手头的这些图片很难手动截屏,所以我想知道有没有办法自动导出给定地理位置的卫星图像。

我正在使用node.js,似乎zombie和phantom.js是模拟人类浏览器的方法,可以从浏览器中检索html,但是这些方法可以渲染谷歌地图html然后允许我来做截图。

【问题讨论】:

  • 您确定这不违反 TOS 吗?
  • 我的问题是关于可能性的,只是为了减轻我对航拍图像进行一些图像处理实验的工作。不用于商业用途。反正
  • 我的回答有帮助吗?有什么问题吗?

标签: google-maps phantomjs zombie.js


【解决方案1】:

是的,使用普通的 PhantomJS 很容易做到这一点。您也可以为此使用 ZombieJS 或 CasperJS。它们使处理许多步骤变得更容易,而不会遇到回调地狱或静态代码。

我添加了点击和打字的必要功能。设置用户代理字符串是必要的,否则 Google 将提供可能无法在(旧)PhantomJS 1.x 引擎上运行的代码。

var page = require('webpage').create(),
    classical = true;

// This userAgent works good with GM
page.settings.userAgent = 'Mozilla/5.0 (Windows NT 6.0) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.41 Safari/535.1';
page.viewportSize = {
    width: 1280,
    height: 800
};

function click(selector){
    page.evaluate(function(selector){
        // taken from here: http://stackoverflow.com/a/15948355
        var ev = document.createEvent("MouseEvent");
        ev.initMouseEvent(
            "click",
            true /* bubble */, true /* cancelable */,
            window, null,
            0, 0, 0, 0, /* coordinates */
            false, false, false, false, /* modifier keys */
            0 /*left*/, null
        );
        document.querySelector(selector).dispatchEvent(ev);
    }, selector);
}

function type(text){
    page.evaluate(function(text, classical){
        var el = document.querySelector(classical ? "#gbqfq" : "#searchboxinput");
        el.value = text;
        el.focus();
    }, text, classical);
    page.sendEvent('keypress', page.event.key.Enter);
}

page.open("https://www.google.com/maps", function (status) {
    if (status !== 'success') {
        console.log('Unable to access network');
        phantom.exit();
    } else {
        if (classical) {
            click("#paneltoggle2");
        }
        setTimeout(function(){
            page.render("1.png");
            click(classical ? "#mv-primary-container > .mv-primary" : "button.widget-minimap-shim");
        }, 1000); // +1 sec
        setTimeout(function(){
            page.render("2.png");
            type("bern");
        }, 11000); //+10 sec
        setTimeout(function(){
            if (classical) {
                click("#paneltoggle2");
            }
        }, 16000); //+5 sec
        setTimeout(function(){
            page.render("3.png");
            phantom.exit();
        }, 21000); //+5 sec
    }
});

如果您使用的是 --ssl-protocol=tlsv1 运行它。使用clipRect 裁剪图像以使控件不可见也可能会有所帮助。

【讨论】:

    猜你喜欢
    • 2010-11-29
    • 1970-01-01
    • 2010-10-04
    • 2011-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多