Reputation: 25
I'm using cheerio
and nodejs
for scrape all the countries available on a site, essentially I did:
const rp = require('request-promise');
const cheerio = require('cheerio');
const options =
{
uri: 'https://uk.soccerway.com/',
transform: function(body)
{
return cheerio.load(body);
}
};
rp(options)
.then(($) =>
{
$('#navbar-left > div:eq(2) > select > option').each(function()
{
console.log($(this).val());
});
}).catch((err) =>
{
console.log(err);
})
I want get all the coutnries of Club Domestic, unfortunately my code return this:
SyntaxError: unmatched pseudo-class :eq
what is that?
UPDATE
new code (iteration will not start):
request('https://uk.soccerway.com/', function(err, resp, html)
{
if (!err)
{
const $ = cheerio.load(html);
var countriesMenu = find($, '#navbar-left > div:eq(2) option');
$(countriesMenu).each(function()
{
console.log($(this).val());
});
}
});
Upvotes: 0
Views: 938
Reputation: 96
As mentioned in the comments, the psuedo-class :eq is not supported in cheerio. You're not using jQuery here, the $ is the cheerio object.
Here's a plugin you can use: https://github.com/watson/cheerio-eq
Upvotes: 2
Reputation: 896
The :eq pseudo-class is not implemented. Calling .eq() should work, though.
Upvotes: 0