Google是否提供对移动设备友好测试的API访问权限? [英] Does Google offer API access to the mobile friendly test?

查看:92
本文介绍了Google是否提供对移动设备友好测试的API访问权限?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一个API,可以访问Google的移动友好测试,可以在 https://www.google.com/webmasters/tools/mobile-friendly/?

Is there an API that allows access to Google's Mobile Friendly Test which can be seen at https://www.google.com/webmasters/tools/mobile-friendly/?

推荐答案

如果您无法通过谷歌搜索找到一个,则可能不存在.

If you can't find one by googling, it probably doesn't exist.

一个有问题的解决方案是使用 PhantomJS 创建一个进程,该进程输入网址,提交网址并进行脏检查追求成果的圆顶.

A hacky solution would be to create a process with PhantomJS that inputs the url, submits it, and dirty-checks the dom for results.

PhantomJS是一款无头WebKit,可使用JavaScript API编写脚本.

PhantomJS is a headless WebKit scriptable with a JavaScript API.

但是,如果您滥用此权限,则Google很有可能会将您的IP地址列入黑名单.少量使用应该没问题.另外请注意,Google可以随时更改其dom结构或类名,因此,如果您的工具突然损坏,请不要感到惊讶.

However, if you abuse this, there is a chance that google will blacklist your ip address. Light use should be fine. Also be aware that google can change their dom structure or class names at any time, so don't be surprised if your tool suddenly breaks.

这是一些未经测试的粗糙代码...

Here is some rough, untested code...

var url = 'https://www.google.com/webmasters/tools/mobile-friendly/';
page.open(url, function (status) {

  // set the url
  document.querySelector('input.jfk-textinput').value = "http://thesite.com";
  document.querySelector('form').submit();

  // check for results once in a while
  setInterval(function(){
    var results = getResults(); // TODO create getResults
    if(results){
      //TODO save the results
      phantom.exit();
    }
  }, 1000);
});

这篇关于Google是否提供对移动设备友好测试的API访问权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆