title: Scraping content from Google search results with request in Node.Js
body: <p>For my Node.Js app I need to get the first page of Google search results but from the <code>.com</code> domain because I need the <code>"People also search for"</code> knowledge graph info, which only shows up on Google.Com.</p>
  
  <p>I figured I can use the <code>request</code> and <code>cheerio</code> modules to scrap content from Google's search results page, but when I try to access the URL I need, i.e. <code>https://www.google.com/search?gws_rd=ssl&amp;site=&amp;source=hp&amp;q=google&amp;oq=google</code> Google automatically redirects me to the <code>.de</code> domain (as I'm based in Germany).</p>
  
  <p>I tried setting it to first load <code>http://www.google.com/ncr</code> url which automatically switches off country-specific redirect in browsers, but it didn't work... </p>
  
  <p>Does anybody know what I could do differently to make it work? </p>
  
  <p>Here's my code... Thank you!</p>
  
  <pre><code>var request = require("request");
  var cheerio = require("cheerio");
  
  function dataCookieToString(dataCookie) {
      var t = "";
      for (var x = 0; x &lt; dataCookie.length; x++) {
          t += ((t != "") ? "; " : "") + dataCookie[x].key + "=" + dataCookie[x].value;
      }
      return t;
  }
  
  function mkdataCookie(cookie) {
      var t, j;
      cookie = cookie.toString().replace(/,([^ ])/g, ",[12],$1").split(",[12],");
      for (var x = 0; x &lt; cookie.length; x++) {
          cookie[x] = cookie[x].split("; ");
          j = cookie[x][0].split("=");
          t = {
              key: j[0],
              value: j[1]
          };
          for (var i = 1; i &lt; cookie[x].length; i++) {
              j = cookie[x][i].split("=");
              t[j[0]] = j[1];
          }
          cookie[x] = t;
      }
  
      return cookie;
  }
  
  var dataCookie = mkdataCookie('MC_STORE_ID=66860; expires=' + new Date(new Date().getTime() + 86409000));
  
  
  request({
      uri: "https://www.google.com/ncr",
      headers: {
          'User-Agent': 'Mozilla/5.0',
          "Cookie": dataCookieToString(dataCookie)
      }
  }, function(error, response, body) {
  
      request({
          uri: "https://www.google.com/search?gws_rd=ssl&amp;site=&amp;source=hp&amp;q=google&amp;oq=google",
          headers: {
              'User-Agent': 'Mozilla/5.0'
          }
      }, function(error, response, body) {
          console.log(body);
          var $ = cheerio.load(body);
  
          $(".kno-fb-ctx").each(function() {
              var link = $(this);
              var text = link.text();
  
              console.log(text);
          });
      });
  });
  </code></pre>