首页 > 解决方案 > 如何从 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

谢谢。

标签: javascriptangularparsingiframe

解决方案


[更新]

这应该可以解决问题

你可以试试这个简单的选择器。假设 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)


推荐阅读