【问题标题】:How to extract link from html script in python?如何从python中的html脚本中提取链接?
【发布时间】:2022-02-03 17:38:02
【问题描述】:

如何使用 Python 从 HTML 脚本中提取 URL?
提供的 HTML:


function download() {
                window.open('https:somelink.com');
        }
        const text = `<div style=\'position: relative;padding-bottom: 56.25%;height: 0;overflow: hidden;\'>
<iframe allowfullscreen=\'allowfullscreen\' src=\'URL\' style=\'border: 0;height: 100%;left: 0;position: absolute;top: 0;width: 100%;\' ></iframe>
</div>`;

function embed() {
                var element = document.getElementById('embed-text');
                console.log(element);
                element.innerHTML = text

        }

期望的输出是:

https://somelink.com

任何帮助都可以。谢谢!

【问题讨论】:

    标签: python html


    【解决方案1】:

    你应该像这样使用正则表达式:

    var urlRegex = /(https?:\/\/[^\s]+)/; // the regex
    // your string
    var input = "<div style=\'position: relative;padding-bottom: 56.25%;height: 0;overflow: hidden;\'><iframe allowfullscreen=\'allowfullscreen\' src=\" https://my-url.com/test \" style=\'border: 0;height: 100%;left: 0;position: absolute;top: 0;width: 100%;\' ></iframe></div>";
    
    console.log(input.match(urlRegex)[1]); // use regex and lot result

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-12
      • 1970-01-01
      • 1970-01-01
      • 2013-08-29
      • 2019-07-10
      • 2017-08-26
      • 2012-04-04
      相关资源
      最近更新 更多