我想对抓取工具和机器人隐藏我的个人数据(电子邮件和电话)。该数据位于锚标记的 href 中。当然,实际用户仍然应该能够拥有功能性的可点击链接。
我正在考虑使用一个简单的 JavaScript 函数来加密和解密数据,以便仅获取 HTML 代码的模式匹配器(*@*.* 等)无法找到实际的电子邮件地址。
所以我的加密功能就是将字符串转换为字符编码列表,将所有列表元素加1,然后将其转换回字符串。请参阅下面的代码。
我的问题:这是向爬虫隐藏数据的适当方法吗?还是说现在每个scraper都渲染JS了?
代码:
function stringToCharCodes(string) {
// Returns a list of the character codes of a string
return [...string].map(c => c.charCodeAt(0))
}
function deobfuscate(obfString) {
// String to character codes
let obfCharCodes = stringToCharCodes(obfString);
// Deobfuscate function (-1)
let deobfCharCodes = obfCharCodes.map(e => e -= 1);
// Character codes back to string
// Use spread operator ...
return String.fromCharCode(...deobfCharCodes);
}
// Result of obfuscate("[email protected]")
let obfEmail = "fybnqmfAfybnqmf/dpn";
document.getElementById("email").href = "mailto:" + deobfuscate(obfEmail);
// Result of obfuscate("31612345678")
let obfPhone = "42723456789";
document.getElementById("whatsapp").href = "https://wa.me/" + deobfuscate(obfPhone);
function obfuscate(string) {
// Obfuscate - Use developer tools F12 to run this once and then use the obfuscated string in your website
// String to character codes
let charCodes = stringToCharCodes(string);
// Obfuscate function (+1)
let obfCharCodes = charCodes.map(e => e += 1);
// Character codes back to string
// Use spread operator ...
return String.fromCharCode(...obfCharCodes);
}
<h1>Obfuscate Email And Phone</h1>
<p>Scrapers without Javascript will not be able to harvest your personal data.</p>
<ul>
<li><a id="email">Mail</a></li>
<li><a id="whatsapp">WhatsApp</a></li>
</ul>
这个问题很难回答,因为没有绝对的真理,但让我尝试一下。
您将永远安全地100%隐藏您的电子邮件。任何以用户可以阅读的方式呈现电子邮件地址的内容也可以通过复杂的电子邮件抓取程序呈现。
一旦我们接受了这一点,剩下的挑战就是在隐藏电子邮件地址的努力和被删除的电子邮件地址造成的损害之间找到合理的平衡。
根据我的经验,使用 html 字符编码对几个字符进行混淆电子邮件和
href=mailto
标记非常简单,但在大多数情况下仍然有效。除此之外,它无需 Javascript 即可渲染。
示例:
<a href="mailto:pet[email protected]">[email protected]</a>
可能会变成类似的东西
<a href="mailto:peter.pan@neverland.org">peter.pan@neverland.de</a>
据说它甚至足以隐藏
mailto:
和 @
。
我猜想,因为有太多的电子邮件地址很容易被收集,所以电子邮件抓取工具不会为此目的使用许多高度复杂的技术。只是没有必要而已。
请记住,无论您多么努力地在可公开访问的网站上隐藏您的电子邮件地址,如果它是众多地址泄漏之一,那么您无论如何都已经失败了。我为不同的服务使用自定义电子邮件地址,并且仅针对这些服务,但我仍然收到垃圾邮件发送到其中一些地址,所以我确信它们以某种方式泄露了。
关于你的方法,我会说是的,这已经足够好了。
我发现防止有人从您的网站上窃取您的电子邮件地址的最佳解决方案是将您的电子邮件隐藏在验证码后面。
您可以自己执行此操作或使用电子邮件链接工具,例如https://VeilMail.io