【问题标题】:Webscraping: Get Link that is only visible on the website not in the htmlWebscraping:获取仅在网站上可见而不在 html 中可见的链接
【发布时间】:2018-09-26 08:19:47
【问题描述】:

所以我在一个网站上,我想获得一个链接。我想获取的链接显示在网站上,但在 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>

【问题讨论】:

  • 你能分享一下这个网站,让我得到更多的解决方案吗?
  • @SmashGuy 该网站是skribbl.io。在该站点上,您必须单击“创建私人房间”按钮,然后您会看到我想要获取的链接。
  • 这里的问题是 url 不会出现在 html 中,它是在您按下 Create Private Room 时动态生成的。我试图追踪它,但由于时间不足而失败。似乎有些复杂。祝你好运。
  • @SmashGuy 好的。感谢您的尝试。

标签: javascript node.js web-scraping nightmare


【解决方案1】:

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

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()"

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

【讨论】:

  • 这不是我真正想做的。邀请字段的值为空。复制按钮已经存在,我想通过网络抓取获取它复制到剪贴板的值。
  • 这不是一个链接。那是由 DOM 事件触发的 javascript。
猜你喜欢
  • 1970-01-01
  • 2021-11-23
  • 1970-01-01
  • 2022-01-17
  • 1970-01-01
  • 1970-01-01
  • 2021-03-11
  • 2021-05-14
  • 2013-06-28
相关资源
最近更新 更多