0

I'm currently trying to recover text between <span> tags on an HTML page with Puppeteer .NET but I can’t. Here’s the part I'm trying to recover:

<span class="nbPoints">12</span>

I have already tried the function EvaluateFunction but I get nothing by trying to print it in the console

var strValueEst = await page.EvaluateFunctionAsync(
  "()=>document.querySelector('#path > path > nbPoints').textContent"
);

I no longer have the exact Java request in mind but that must not be the problem because I copy it via inspect the element and copy the full path JS (in Chrome).

  • Can you share a little bit more of the HTML you want to scrap? It's not clear how that selector you get a proxy element. – hardkoded Jan 15 '20 at 11:25
  • @hardkoded Hello thank you for your answer, my example may not be very clear, this part will be clearer, this is the second element that I am trying to obtain, it is a number of points. here is the code which is contained in a
    itself in a
    : https://ibb.co/rw1xnPc Sorry I'm new to stackoverflow and can't find how to put code in a comment
    – Shadow Legacy Jan 15 '20 at 13:20
  • Are you sure that the selector will work? – hardkoded Jan 15 '20 at 14:47
  • @hardkoded I think the selector is ok, I extract it from inspect the element, right click, copy and copy the JS path. I then replace what is after => with: document.querySelector ("# loyaltyProgramZone> div> div.loyalty-program-left> p.nb-total-points> span.nbPoints"). Thank you again for your help – Shadow Legacy Jan 15 '20 at 16:23
  • When I enter it in the console it returns me: 12. It's so strange – Shadow Legacy Jan 15 '20 at 16:42

1 Answers1

0

Try to use "innerText" except "textContent".

var strValueEst = await page.EvaluateFunctionAsync(
  "()=>document.querySelector('#path > path > nbPoints').innerText"
);
DanilaNV
  • 169
  • 2
  • 4
  • 13