Document querySelector on a variable?

Document querySelector on a variable?


<!DOCTYPE html>
<title>JS Scrape Example</title>
<script src=""></script>
<script type="text/javascript">

$.get('', function(response) {    
var selector = '#site > div > div > div.pure-u-1.pure-u-lg-1-3.cloudflare > div > div:nth-child(3) > ul > li:nth-child(1) > a';
var info = $(selector).first();


I’m working on the above code. The goal being to scrape the webhost (in this case Cloudflare). I have the selector found through Chrome’s developer console. However I cannot use javascript’s built in querySelector on the value of a variable (Even though it’s HMTL). What is the best way to go about continuing to scrape this information?


Not sure if there is any easy way to do this in javascript, but it is super easy in Node:

var request = require('request');
var cheerio = require('cheerio');

module.exports = function(done){
  var url = ""; 

  request(url, function(err, res, html){
      var $ = cheerio.load(html);

      var title = $(".dotd-title h2").html().trim();

      return done(title);

This gets the title of the free ebook on