簡體   English   中英

如何從 python 中的 html 腳本中提取鏈接?

[英]How to extract link from html script in python?

如何從帶有 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

        }

所需的 output 將是:

https://somelink.com

任何幫助都可以。 謝謝!

你應該像這樣使用正則表達式:

 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM