简体   繁体   English

<span>使用 puppeteer-sharp 将</span>文本抓取到一个<span>类中</span>

[英]Scraping text into a <span> class with puppeteer-sharp

I'm currently trying to recover text between <span> tags on an HTML page with Puppeteer .NET but I can't.我目前正在尝试使用 Puppeteer .NET 恢复 HTML 页面上<span>标记之间的文本,但我不能。 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我已经尝试过EvaluateFunction函数,但是尝试在控制台中打印它却一无所获

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).我不再考虑确切的 Java 请求,但这一定不是问题,因为我通过检查元素复制它并复制完整路径 JS(在 Chrome 中)。

Try to use "innerText" except "textContent".尝试使用除“textContent”之外的“innerText”。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM