taoqf / node-html-parser

A very fast HTML parser, generating a simplified DOM, with basic element query support.
MIT License
1.11k stars 107 forks source link

Query Throws when the element exists #224

Closed L1lith closed 1 year ago

L1lith commented 1 year ago

I try running this query but it seems to fail incorrectly.

doc.querySelector(".band:nth-of-type(3) .col-md-4:nth-of-type(2) h2")

Error Message:

TypeError: Cannot read properties of null (reading 'length')
    at nthOfType (/Users/ADMIN/projects/melonjs.org/node_modules/css-select/lib/pseudo-selectors/filters.js:81:42)
    at cachedDescendant (/Users/ADMIN/projects/melonjs.org/node_modules/css-select/lib/general.js:71:55)
    at tag (/Users/ADMIN/projects/melonjs.org/node_modules/css-select/lib/general.js:48:60)
    at cachedDescendant (/Users/ADMIN/projects/melonjs.org/node_modules/css-select/lib/general.js:71:55)
    at tag (/Users/ADMIN/projects/melonjs.org/node_modules/css-select/lib/general.js:48:60)
    at findOne (/Users/ADMIN/projects/melonjs.org/node_modules/node-html-parser/dist/matcher.js:68:13)
    at findOne (/Users/ADMIN/projects/melonjs.org/node_modules/node-html-parser/dist/matcher.js:74:24)
    at findOne (/Users/ADMIN/projects/melonjs.org/node_modules/node-html-parser/dist/matcher.js:74:24)
    at findOne (/Users/ADMIN/projects/melonjs.org/node_modules/node-html-parser/dist/matcher.js:74:24)
    at findOne (/Users/ADMIN/projects/melonjs.org/node_modules/node-html-parser/dist/matcher.js:74:24)

When I run the same query in my browser while browsing the HTML page, it returns the \<h2> element successfully.

Relevant source code & HTML files

L1lith commented 1 year ago

@taoqf It appears I'm still getting that error, I'm also getting it with this query .band:nth-of-type(3) .col-md-4:nth-of-type(3) blockquote p I do admit the query is quite complicated, is this something the library is not intended for?

taoqf commented 1 year ago

So sorry for that, I did not see the html file.

L1lith commented 1 year ago

So sorry for that, I did not see the html file.

Thank you 🥳 everything worked like a charm!