question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Malformed attribute selector

See original GitHub issue

I’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:closed
  • Created 6 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
gkatsevcommented, Feb 27, 2018
1reaction
gkatsevcommented, Feb 27, 2018

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-

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found