Node x-ray crawling data from collection of url

I'm trying to scrape a list in a site that leads to other pages that has the same formatting.

I was able to create a collection of all the a tags, but when I try to visit a collection of pages, the key I try to create with it doesn't get added in my returned object.

Here's an example of what I'm trying to do with stack overflow:

var Xray = require('x-ray');
var x = Xray();
x('http://stackoverflow.com/', {
    title: x(['a@href'], 'title'),
}) (function(err, obj) {
    console.log(obj);
});

I'm expecting my obj.title to be a list of titles of all the a href pages, instead I just get an empty object.

However if I were to try just using the first a href then I get the title no problem.

var Xray = require('x-ray');
var x = Xray();
x('http://stackoverflow.com/', {
    title: x('a@href', 'title'),
}) (function(err, obj) {
    console.log(obj);
});

Has anyone run into this problem before?

Answers


I ran into that problem before and my solution goes like this:

var Xray = require('x-ray');
var x = Xray();
x('http://stackoverflow.com/', {
    title: x('a', [{links:'@href'}])
}) (function(err, obj) {
    obj.forEach(function(links.link) {
        x(links.link, "title")(function(err, data){
                console.log(data) // should print the title
        });
});

Let me know if you run into any problems.


You could Use X-ray's Crawling to anoth site

var Xray = require('x-ray');
var x = Xray();

x("http://stackoverflow.com/", {
  main: 'title',
  image: x('#gbar a@href', 'title'), // follow link to google images 
})(function(err, obj) {
/*

Need Your Help

Excel formula to determine if any cells in a range contain a value

excel excel-formula worksheet-function

This is probably quite a basic thing to do, but I've been looking around the internet and have tried several ways of doing it to no avail.

Adding items to a new column is not working

c# winforms listview

I am trying to add some items from Arrays to a new column in a listview, this is what i am trying to do: