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
deep-learning
ng-idle
interface
jelastic
saml-2.0
composite-primary-key
solver
vscode-extensions
access
simulink
web-hosting
gembox-spreadsheet
modal-dialog
mel
project-intu
spring-social
stellar.js
alpacajs
production
bourbon
libigl
pchart
xunit
expressionengine3
interbase
gpio
rpgle
gp
eviews
record
jbutton
wacom
dsx-desktop
github3.py
twos-complement
carriage-return
imx6
python-pptx
playframework-2.1
reactivekit
jvmti
signals-slots
preloader
wc
signal-strength
flask-login
oim
monkey-testing
yii2-api
reportservice2010
tf
remedy
hadoop-2.7.2
flex4.6
resourcemanager
respondcms
omniauth-facebook
upx
libvlc
xenomai
django-urls
intel-c++
poppler
rpart
skspritenode
botan
ms-access-2000
osc
document-repository
ejb-2.x
ssis-data-flow
rickshaw
genymotion-call
mdichild
build-script
gnumeric
cocoalibspotify-2.0
unit-of-work
workitem
kaleidoscope
actiondispatch
composite-component
video-codecs
onload-event
robotlegs
sentestingkit
predicatebuilder
infobright
node-redis
django-paypal
web-application-project
cuda.net
xpsdocument
change-management
leader
idatareader

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