Malformed attribute selector
See original GitHub issueI’m trying the following and getting an error:
var htmlFiles = [];
$("resource[href*='.htm'][d2l_2p0:material_type='content']").each(function () {
htmlFiles.push($(this).attr("href"));
});
return htmlFiles;
\path\to\node_modules\css-what\index.js:152
throw new SyntaxError("Malformed attribute selector: " + selector);
^
SyntaxError: Malformed attribute selector: d2l_2p0:material_type='content']
at parseSelector (\path\to\node_modules\css-what\index.js:152:12)
at parse (\path\to\node_modules\css-what\index.js:82:13)
at compileUnsafe (\path\to\node_modules\css-select\lib\compile.js:31:14)
at select (\path\to\node_modules\css-select\index.js:18:49)
at CSSselect (\path\to\node_modules\css-select\index.js:41:9)
at initialize.exports.find (\path\to\node_modules\cheerio\lib\api\traversing.js:40:21)
at initialize.module.exports (\path\to\node_modules\cheerio\lib\cheerio.js:86:18)
at new initialize (\path\to\node_modules\cheerio\lib\static.js:29:20)
at initialize (\path\to\node_modules\cheerio\lib\static.js:26:14)
at Object.scanForContentFiles [as contentFiles] (\path\to\lib\scanner\content-files.js:6:2)
I’m fairly certain that I’ve used this exact selector before with no problem. I’m guessing the problem is the colon (:
) in the selector which is fairly common in XML.
Please note that I instantiated the cheerio object with the following options:
var cheerioOptions = {
normalizeWhitespace: true,
xmlMode: true,
decodeEntities: false
};
It should be noted that I can access the value of the attribute via the attr method so the following does work (-around):
var htmlFiles = [];
$("resource[href*='.htm']").each(function () {
if($(this).attr("d2l_2p0:material_type") === "content") {
htmlFiles.push($(this).attr("href"));
}
});
return htmlFiles;
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
Cheerio: SyntaxError: Malformed attribute selector: object ...
Cheerio is using Sizzle, which does not like the "malformed" attribute (used to be a problem in IE 7-9 as well)... Like jQuery,...
Read more >Beautiful Soup Differences - Soup Sieve
A modern CSS selector library for Beautiful Soup. ... If you get an error complaining about a malformed attribute, you may need to...
Read more >Parsing issue with recent version (soupsieve exception)
Attribute selectors are captured as a whole, valid selector. So currently, if the attribute selector doesn't match, we see an invalid `[` character,...
Read more >[Solved]-Malformed attribute selector Cheerio-node.js
Cheerio is giving me only part of src attribute value of img? ... Can I load a local html file with the cheerio...
Read more >Help my HTML Extractor Stopped Working - FME Community
SelectorSyntaxError'>: Malformed attribute selector at position 0 ... I have other CSS selectors configured the same way that are still ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Cool, made a PR here: https://github.com/cheeriojs/cheerio/pull/1151
Would you accept a PR to make a small note of this in the README? Maybe a sentence at the end of this section? https://github.com/cheeriojs/cheerio#-selector-context-root-