jQuery selector inside selector with NodeJS + Node.io

583 Views Asked by At

I have a NodeJS app that is trying to use JQuery to scrape a webpage. Within the web page I am trying to scrape:

<div class="gs_rt">
<a href="www.google.com">someTextHere</a>
</div>

I'd like to get 'someTextHere' by calling a jQuery selector within the first jQuery selector.

$('.gs_r .gs_rt').each(function(index,result) {
    //fetches div okay
var test = $(this).find('a');
console.log(test);              
});

Unfortunately, it seems like 'this' is pointing to my Node.io Job object. Also, 'index' doesn't seem to work (how do I get the index of the current object fetched by 'each'?).

I'm not really sure what is happening. help anybody? :)

1

There are 1 best solutions below

0
On

I figured out the reason why. Node.io has built-in selectors callable with $() but it does not actually use jQuery.

See https://github.com/chriso/node.io/wiki/API---CSS-Selectors-and-Traversal-methods for the API.

Instead, one should do

var jQuery = require('jquery);

and use their built-in selectors.