0

I have HTML structure like this :

<div>
   <span id="author-comment-2">Author</span>
   <div>
     <div class="author">I don't want this text</div>
   </div>
</div>

<div>
   <span id="author-comment-3">Author</span>
   <div>
     <div class="author">I want this text</div>
   </div>
</div>

<div>
   <span id="author-comment-4">Author</span>
   <div>
     <div class="author">I don't want this text</div>
   </div>
</div>

I just want the text 'I want this text'. So how can I get it by using Puppeteer because it is don't have ID or Class that I can use to reference to it?

Thank you for advance answer.

pors
  • 191
  • 2
  • 3
  • 15
  • 1
    Does this answer your question? [What is syntax for selector in CSS for next element?](https://stackoverflow.com/questions/3660046/what-is-syntax-for-selector-in-css-for-next-element) – mbit Feb 27 '20 at 21:10

1 Answers1

2

Try this:

page.$eval('#author-comment-3 + div>.author', element => {
  return element.innerHTML
})
F.NiX
  • 1,457
  • 3
  • 12
  • 20