I'm trying to get all items in a specific div
that is already addressed.
But after using children()
it only shows the first item instead of a list of whole children.
Here is the source:
And here is my code:
> const html = res.data;
> const $ = cheerio.load(html);
> const data = $('div[id="thepics"]');
> console.log(data);
And its result:
LoadedCheerio {
'0': <ref *1> Node {
type: 'tag',
name: 'div',
namespace: 'http://www.w3.org/1999/xhtml',
attribs: [Object: null prototype] {
style: 'margin:-5px 0px 10px 0px',
id: 'thepics'
},
'x-attribsNamespace': [Object: null prototype] { style: undefined, id: undefined },
'x-attribsPrefix': [Object: null prototype] { style: undefined, id: undefined },
children: [ [Node] ],
parent: Node {
type: 'tag',
name: 'div',
namespace: 'http://www.w3.org/1999/xhtml',
attribs: [Object: null prototype],
'x-attribsNamespace': [Object: null prototype],
'x-attribsPrefix': [Object: null prototype],
children: [Array],
parent: [Node],
prev: [Node],
next: [Node]
},
prev: Node {
type: 'tag',
name: 'div',
namespace: 'http://www.w3.org/1999/xhtml',
attribs: [Object: null prototype],
'x-attribsNamespace': [Object: null prototype],
'x-attribsPrefix': [Object: null prototype],
children: [],
parent: [Node],
prev: [Node],
next: [Circular *1]
},
next: Node {
type: 'tag',
name: 'div',
namespace: 'http://www.w3.org/1999/xhtml',
attribs: [Object: null prototype],
'x-attribsNamespace': [Object: null prototype],
'x-attribsPrefix': [Object: null prototype],
children: [Array],
parent: [Node],
prev: [Circular *1],
next: [Node]
}
},
length: 1,
options: { xml: false, decodeEntities: true },
_root: <ref *2> LoadedCheerio {
'0': Node {
type: 'root',
name: 'root',
parent: null,
prev: null,
next: null,
children: [Array],
'x-mode': 'no-quirks'
},
length: 1,
options: { xml: false, decodeEntities: true },
_root: [Circular *2]
},
prevObject: <ref *2> LoadedCheerio {
'0': Node {
type: 'root',
name: 'root',
parent: null,
prev: null,
next: null,
children: [Array],
'x-mode': 'no-quirks'
},
length: 1,
options: { xml: false, decodeEntities: true },
_root: [Circular *2]
}
}
And after try to log data.children()
the result is:
LoadedCheerio {
'0': Node {
type: 'script',
name: 'script',
namespace: 'http://www.w3.org/1999/xhtml',
attribs: [Object: null prototype] {},
'x-attribsNamespace': [Object: null prototype] {},
'x-attribsPrefix': [Object: null prototype] {},
children: [ [Node] ],
parent: Node {
type: 'tag',
name: 'div',
namespace: 'http://www.w3.org/1999/xhtml',
attribs: [Object: null prototype],
'x-attribsNamespace': [Object: null prototype],
'x-attribsPrefix': [Object: null prototype],
children: [Array],
parent: [Node],
prev: [Node],
next: [Node]
},
prev: null,
next: null
},
length: 1,
options: { xml: false, decodeEntities: true },
_root: <ref *1> LoadedCheerio {
'0': Node {
type: 'root',
name: 'root',
parent: null,
prev: null,
next: null,
children: [Array],
'x-mode': 'no-quirks'
},
length: 1,
options: { xml: false, decodeEntities: true },
_root: [Circular *1]
},
prevObject: LoadedCheerio {
'0': Node {
type: 'tag',
name: 'div',
namespace: 'http://www.w3.org/1999/xhtml',
attribs: [Object: null prototype],
'x-attribsNamespace': [Object: null prototype],
'x-attribsPrefix': [Object: null prototype],
children: [Array],
parent: [Node],
prev: [Node],
next: [Node]
},
length: 1,
options: { xml: false, decodeEntities: true },
_root: <ref *1> LoadedCheerio {
'0': [Node],
length: 1,
options: [Object],
_root: [Circular *1]
},
prevObject: <ref *1> LoadedCheerio {
'0': [Node],
length: 1,
options: [Object],
_root: [Circular *1]
}
}
}