Closed alejodiazg closed 5 years ago
:+1: Or the example is misleading, items, or this is a bug.
Same problem here, array of objects returns single item event though there are multiple items available.
I encounter the same issue. If this is a bug, I'm happy to fix it.
@damonmcminn the point is, using a DOM selector, like jQuery, what is the expected output?
@Kikobeats I believe the expected result is an array of all the elements that match the query selector, thats what the example tells us to expect.
Unfortunately I had to stop using x-ray for the scraping that i was doing, but i'll be glad to give more feedback, maybe share the whole code (I think I still have it) if its needed.
Investigating deeper, I believe I misunderstood the docs and, for me at least, it's a user error. The below works as expected:
var Xray = require('x-ray');
var x = new Xray();
var hn = 'https://news.ycombinator.com';
var a = x(hn, x('.itemlist .athing', [{link: '.title span a@href'}]));
var b = x(hn, '.itemlist .athing', [{link: '.title span a@href'}]);
var multiple = x(hn, { a, b });
multiple((err, data) => console.log(err || data));
output
{ a:
[ { link: 'https://news.ycombinator.com/from?site=cloud.google.com' },
{ link: 'https://news.ycombinator.com/from?site=samaltman.com' },
{ link: 'https://news.ycombinator.com/from?site=windows.com' } ... ],
b:
[ { link: 'https://news.ycombinator.com/from?site=cloud.google.com' },
{ link: 'https://news.ycombinator.com/from?site=samaltman.com' },
{ link: 'https://news.ycombinator.com/from?site=windows.com' } ... ] }
I was following this example (scoping selectors)
and I thought it meant inside mat.io find all .item and add an object with the defined structure to an array in items, but it seems it only gets the first .item. How do I make something similar but with each .item that is in the page that im scraping?
im using this selector (is complicated the page is really messy) "table[width=748]:last-of-type tr:not(:first-of-type)" and I have multiple tr that are after the first one, but with that I only get one (the second one cause my selector makes it ignore the first)
my code
the console.log output