matthewmueller / x-ray

The next web scraper. See through the <html> noise.
MIT License
5.87k stars 349 forks source link

:first, :last :n-child selectors #256

Closed deed02392 closed 5 years ago

deed02392 commented 7 years ago

Subject of the issue

When attempting to use the pseudo-selectors to get the n'th child items of nodes, I get the error:

[SyntaxError: unmatched pseudo-class :last]

Your environment

Steps to reproduce

x(markup, {
    raw_table: 'table.schedule@html',
    sched_type: ['tr@class'],
    date: ['td.date'],
    descr: ['tr td:last'] // This line
})(

Expected behaviour

descrshould be a collection of the innerText of all the last columns of all the rows parsed from 'markup'

Actual behaviour

Syntax error. Exit.

kyleoliveiro commented 7 years ago

Shouldn't the selector be :last-child?

Jacse commented 7 years ago

As @kyleoliveiro mentions the correct selectors are :first-child, :last-child, :nth-child

dzcpy commented 5 years ago

Try this:

x(markup, {
    raw_table: 'table.schedule@html',
    sched_type: ['tr@class'],
    date: ['td.date'],
    descr: ['tr td:nth-last-child(1)'] // This line
})