cheerio


confused about cheerio nextUntil


I am trying to parse some html using cheerio, and for one set of tags cheerio.nextUntil() seems to work as expected, but for another set it doesn't
this is the code
(function () {
const cheerio = require('cheerio');
const html = `
<h2>Reset spent time for an issue</h2>
<p>Resets the total spent time for this issue to 0 seconds.</p>
<pre><code>POST /projects/:id/issues/:issue_iid/reset_spent_time
</code></pre>
<h2>Get time tracking stats</h2>
<pre><code>GET /projects/:id/issues/:issue_iid/time_stats
</code></pre>`;
let $ = cheerio.load(html);
$('h2').each(function(index,element) {
let name = $(this).text();
let description = $(this).next('p').text();
let url = $(this).nextUntil('pre').next('pre').text().trim();
console.log({
name,
description,
url
});
});
})();
the result I'm getting is
{ name: 'Reset spent time for an issue',
description: 'Resets the total spent time for this issue to 0 seconds.',
url: 'POST /projects/:id/issues/:issue_iid/reset_spent_time' }
{ name: 'Get time tracking stats', description: '', url: '' }
I expect the second description to be '', but don't understand why the second url is blank
if I change the code to
let url = $(this).nextUntil('pre').next('pre').text().trim();
let foo = $(this).next().text();
console.log({
name,
description,
url,
foo
});
I get
{ name: 'Get time tracking stats',
description: '',
url: '',
foo: 'GET /projects/:id/issues/:issue_iid/time_stats\n ' }
so, foo is what I expected
nextUntil() does this
Gets all the following siblings up to but not including the element
matched by the selector, optionally filtered by another selector.
so, because it says "following siblings, but not the matched element" and the next sibling is the matched element, so it doesn't match it, and it's not included , then next() doesn't then work ?
if so, what mechanism could I use to get the desired result ?
thanks

Related Links

confused about cheerio nextUntil
Get the text of the current node only
Accessing the text of a class that contains other elements using Cheerio
cheerio reading children of script tag
how to extract info in this kind of html using cheerio?
Cheerio not finding table content

Categories

HOME
android
phantom-dsl
awk
apache-flink
android-studio-2.2
youtube-data-api-v3
static
pclxl
yandex
telegram-bot
square
babeljs
polling
nuget-package
special-characters
octave
endeca
project-intu
mautic
datastage
shared-libraries
scrolltop
libusb
package-managers
atlassian-stash
firefox-addon
chargify
wolframalpha
imessage
sigma.js
boost-icl
poedit
articulate-storyline
short-url
perlbrew
fable-f#
motion-detection
shared
jasmine-node
sqsh
constexpr
autodesk-designautomation
complex-numbers
paragraph
r-grid
laravel-eloquent
code-snippets
card.io
arduino-ide
least-squares
imx6
numpy-broadcasting
latitude-longitude
google-knowledge-graph
release
filesystemwatcher
google-data-api
show-hide
stylecop
procfile
xbmc
chai-as-promised
facebook-pixel
twilio-click-to-call
tf
openblas
java-bytecode-asm
check-mk
lsyncd
sandcastle
donations
visual-studio-2008-sp1
docpad
autosar
centrifuge
tinkerpop3
jboss-tools
lua-telegram-bot
lz77
fuzzywuzzy
ellucian-scribe
toast
pypiserver
jdi
iced-coffeescript
avahi
android-broadcast
broadband
exceldatareader
theos
ssis-data-flow
entry-point
gii
ignite-ui
parallel-testing
ray
buffering
cfcache
windows-embedded-standard
rfc5322
mvc-editor-templates
jquery-1.9
resource-management
fusefabric
predicatebuilder
box2d-iphone
lr
clrstoredprocedure
xui
cruisecontrol.rb
scrollbars
filesystemobject
lobo-cobra

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App