Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Google offer API access to the mobile friendly test?

Tags:

google-api

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/?

like image 990
user3264918 Avatar asked Feb 06 '26 19:02

user3264918


2 Answers

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

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 is a headless WebKit scriptable with a JavaScript API.

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);
});
like image 160
posit labs Avatar answered Feb 09 '26 10:02

posit labs


There is an option in pagespeed api

https://www.googleapis.com/pagespeedonline/v3beta1/mobileReady?url={url}&key={api key}

key can be obtained form google cloud platform.

like image 44
najeeb Avatar answered Feb 09 '26 10:02

najeeb