B
B
blackdracon2018-09-27 10:01:46
Parsing
blackdracon, 2018-09-27 10:01:46

How to add check of two classes?

Good afternoon, there is such a piece of script that receives h3 with the class "r" and displays true / false, but now there is always r and I want to do this - if one r is false, if two r are true. Tell me how to add a check for the presence of 2 "r" classes at the same time. I will be very grateful, good code to everyone.

function isIndexed(page,ignoreCase) {
  var urls=[],RETRIES=5;

  if(!page)return;
  
  if(page.indexOf("://")!==-1)page=page.split("://")[1].trim();

  var url='https://www.google.com/search?q='+encodeURIComponent(page)+'&fp=1&dpr=2&sns=1&pf=p&tch=1&filter=0';

  if(page.slice(-1)=="/")page=page.slice(0,-1);
    
  try {
    var serp=UrlFetchApp.fetch(url,{muteHttpExceptions:true,method:"GET",followRedirects:true});
    var result=serp.getContentText().split('/*""*/');
    
    var searchResults,serpResults,isIndexed=false;
    
    for(var i=2;i<result.length-1;i++) { 
      searchResults=JSON.parse(result[i]);
      serpResults=searchResults.d.split('<h3 class="r"><a href="/url?q=');
      isIndexed=findIndexedURL(serpResults, page, ignoreCase);
      if(isIndexed) return "Yes";
    }
    return "No";
    
  } catch(e) { return "No"; }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question