想象一个网络爬虫,抓取网站以查找电子邮件和联系信息。下面我介绍了如何向访问者展示我的电子邮件,请告诉我您对为什么或为什么不这样做的想法?
<button id="reqBtn" type = "button" class = "btn btn-success btn-lg" onclick="showEmail()">
Request
</button>
<script type="text/javascript">
function showEmail(){
var array = ['t@','m.com'];
document.getElementById('reqBtn').innerHTML = 'suppor'+array[0]+'mydomai'+array[1];
}
</script>
这在我的网页上显示了一个按钮,单击“请求”按钮后,它将显示电子邮件。我背后的逻辑是,由于我将电子邮件的“.com”和“@”部分存储在一个数组中,因此 HTML 抓取工具无法将这些部分放在一起来查找电子邮件以及用户操作首先按下按钮。这有效吗?
最佳答案
<button id="reqBtn" type="button" class="btn btn-success btn-lg" onclick="showEmail()">Request</button>
<script type="text/javascript">
function showEmail(){
var email = window.atob('dEBtLmNvbQ==');
document.getElementById('reqBtn').innerHTML=email;
}
</script>
您可以使用window.atob()
方法。
根据 MDN:
The WindowOrWorkerGlobalScope.atob() function decodes a string of data which has been encoded using base-64 encoding. You can use the btoa() method to encode and transmit data which may otherwise cause communication problems, then transmit it and use the atob() method to decode the data again.
因此,如果您的电子邮件是 t@m.com,您可以使用 .btoa()
直接对其进行编码,然后获取输出:
window.btoa('t@m.com')
// result: "dEBtLmNvbQ=="`
并且在您的代码中您可以使用 .atob()
方法:
<button id="reqBtn" type="button" class="btn btn-success btn-lg" onclick="showEmail()">
Request
</button>
<script type="text/javascript">
function showEmail(){
var email = window.atob('dEBtLmNvbQ==');
document.getElementById('reqBtn').innerHTML=email;
}
</script>
关于javascript - 这是防止网络抓取工具在我的网站上找到我的电子邮件的有效方法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42793692/