javascript - 如何从 iframe html 代码中解析 url?
问题描述
我在 db 中有一个 vimeo iframe 代码。
<iframe src="https://player.vimeo.com/video/33535353" width="650" height="375" frameborder="0" allow="autoplay; fullscreen" allowfullscreen></iframe>
我如何从这个 iframe 代码中获取链接。
预期结果:https://vimeo.com/33535353
谢谢。
解决方案
[更新]
这应该可以解决问题
你可以试试这个简单的选择器。假设 src 在开头
let URL = `<iframe src="https://player.vimeo.com/video/33535353" width="650" height="375" frameborder="0" allow="autoplay; fullscreen" allowfullscreen></iframe>`;
let updatedURLArr = URL.match(/"(.*?)"/)
var updatedURL = updatedURLArr[1].replace('https://player.vimeo.com/video','https://vimeo.com');
console.log(updatedURL)
推荐阅读
- javascript - Nashorn 能否将 JavaScript 库移植到交叉构建的 Scala.js 项目的 JVM 端?
- shell - VBScript 使用 SendKeys 发送新行的行为很奇怪
- python - 用 Beautiful Soup 用 Python 抓取政府网站
- python-3.x - 使用排序索引重新排列 3-D 数组?
- elixir - Phoenix:有没有办法在另一个视图中给一个视图起别名?
- c# - 错误:(412)当前在 blob 上存在租约,请求中未指定租约 ID
- instagram - 查找用于 API 访问的 Instagram 用户 ID(截至 2018 年)
- java - Springboot 2.0 无法访问 SQL Server 数据库
- java - 在 Java 中将多行写入文件 (.txt)
- python - 关于 Python 上的一个函数