[英]Cheerio `text()` empty string for span tag
I've loaded to Cheerio a product from belk.com . 我已经从belk.com向Cheerio加载了产品 。 I can get to the price element using the selector
[class="price"]
, but when I try to get its text using text()
, I get an empty string. 我可以使用选择器
[class="price"]
来获取价格元素,但是当我尝试使用text()
获取其文本时,我得到了一个空字符串。
If I do $('class="price"').contents()
I can see a child with the text, but it seems like the wrong way to go. 如果我执行
$('class="price"').contents()
我可以看到一个带有文本的孩子,但这似乎是错误的方法。 Is there a generic method to getting the element text? 是否有获取元素文本的通用方法?
Thanks! 谢谢!
That HTML has both p
and span
tags with class price
, so you'll need to be more specific. 该HTML具有带有class
price
p
和span
标签,因此您需要更加具体。 This works for me $('p.price span.price').text()
这对我
$('p.price span.price').text()
Apparently, this is expected node
REPL behavior. 显然,这是预期的
node
REPL行为。
The values tested negative for null and in debugger mode I could see the scraped value from Cheerio. 值测试为负值是否为null,在调试器模式下,我可以看到来自Cheerio的抓取值。 Because it contained
\\r
characters, printing it to console looked as if it's an empty string. 因为它包含
\\r
字符,所以将其打印到控制台看起来好像是一个空字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.