https://www.apotek1.no/vaare-apotek/ostfold/raade-474
在上面网站的中心,你可以看到一个电子邮件地址被封装在"mailto“html部分中。使用jQuery可以相当容易地将此邮件作为字符串获取,如下所示:
$('a[href^="mailto:"]').text然而,当我想要在cheerio库中使用node.js (它应该像jquery一样工作)时,它就不能工作了。
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部分获取地址?
发布于 2018-05-10 09:08:06
$('a[href^="mailto:"]').attr("href")尝试使用这个,它将返回href属性值,在您可以替换mailto: like之后
$('a[href^="mailto:"]').attr("href").replace(‘mailto:’, ‘’)希望这能对你有所帮助。
https://stackoverflow.com/questions/50264037
复制相似问题