首页 > 解决方案 > Webscraping:获取仅在网站上可见而不在 html 中可见的链接

问题描述

所以我在一个网站上,我想获得一个链接。我想获取的链接显示在网站上,但在 html 文件中不可见。有一个复制按钮,可将链接复制到剪贴板。我想获取链接,有人知道如何获取吗?html 看起来像这样:

<div class="containerInvite">
      <div class="title">Invite your friends!</div>
      <div class="inviteBar">
        <input type="text" readonly id="invite">  --Here should be the link
        <button class="button btn btn-primary" 
         id="inviteCopyButton">Copy</button> --The Button that copies the link
      </div>
    </div>

标签: javascriptnode.jsweb-scrapingnightmare

解决方案


id="invite"要从 javascript中读取输入值,请使用:

document.getElementById("invite").value;

如果您希望按钮将值复制到剪贴板,请创建一个函数

function copyLink() {
  //Get the text field
  var copyText = document.getElementById("invite");
  //Select the text field
  copyText.select();
  //Copy the text inside the text field
  document.execCommand("copy");
}

然后加

onclick="copyLink()"

在您的按钮中。或附加一个“点击”事件


推荐阅读