首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Node: Find mailto: section with cheerio

Node: Find mailto: section with cheerio
EN

Stack Overflow用户
提问于 2018-05-10 08:59:09
回答 1查看 370关注 0票数 1

https://www.apotek1.no/vaare-apotek/ostfold/raade-474

在上面网站的中心,你可以看到一个电子邮件地址被封装在"mailto“html部分中。使用jQuery可以相当容易地将此邮件作为字符串获取,如下所示:

代码语言:javascript
复制
$('a[href^="mailto:"]').text

然而,当我想要在cheerio库中使用node.js (它应该像jquery一样工作)时,它就不能工作了。

代码语言:javascript
复制
 let      $  = cheerio.load(html) // launching cheerio with html code requested from website
 let mailto  = $('a[href^="mailto:"]').text // this will give me empty string
 let mailto1 = $('a[href^="mailto:"]').text() // this will return whole body of the function

如何使用cheerio从mailto部分获取地址?

EN

回答 1

Stack Overflow用户

发布于 2018-05-10 09:08:06

代码语言:javascript
复制
$('a[href^="mailto:"]').attr("href")

尝试使用这个,它将返回href属性值,在您可以替换mailto: like之后

代码语言:javascript
复制
$('a[href^="mailto:"]').attr("href").replace(‘mailto:’, ‘’)

希望这能对你有所帮助。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50264037

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档