Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot get trivial read property innerHTML example working #19

Closed
danneu opened this issue Oct 31, 2017 · 3 comments
Closed

Cannot get trivial read property innerHTML example working #19

danneu opened this issue Oct 31, 2017 · 3 comments

Comments

@danneu
Copy link

danneu commented Oct 31, 2017

Working through the README, I'm having trouble getting innerHTML to return anything beyond undefined.

x('select div {0,}[0] | read property textContent', '<div>hello</div>')
//=> 'hello'
x('select div {0,}[0] | read property innerHTML', '<div>hello</div>')
//=> undefined
@gajus
Copy link
Owner

gajus commented Oct 31, 2017

Is this using the cheerio or browser executor?

@gajus
Copy link
Owner

gajus commented Oct 31, 2017

The logic is pretty trivial:

const getPropertyValue = (node: Object, name: string): mixed => {
if (name === 'textContent') {
return node.text();
}
// @see https://github.com/cheeriojs/cheerio/issues/944
if (name === 'outerHTML') {
return node.clone().wrap('<div>').parent().html();
}
// @see https://github.com/cheeriojs/cheerio/issues/993
if (name === 'childNodes') {
return node[0].childNodes;
}
return node.prop(name);
};

I am going to guess that for whatever reason innerHTML returns undefined in cheerio. It looks like it requires adding another if condition that checks if property name is innerHTML and uses .html() method to return the HTML.

@gajus gajus closed this as completed in 82824dc Oct 31, 2017
@gajus
Copy link
Owner

gajus commented Oct 31, 2017

It is a bug in cheerio, cheeriojs/cheerio#1099.

I have patched it locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants