功能:获取音乐记录的Youtube URL
import urllib.request import re def fetch_webpage(url): # 使用urllib.request.urlopen打开网页 with urllib.request.urlopen(url) as response: # 读取网页内容,response.read() 获取的是字节数据 html_content = response.read() # 将字节数据解码为字符串 html_text = html_content.decode('utf-8') return html_text def find_youtube_urls(html_text): # 使用正则表达式查找所有的 URL urls = re.findall(r'href=["\'](https?://[^"\' ]+)', html_text) # 筛选出包含 "youtube.com" 的 URL youtube_urls = [url for url in urls if "youtube.com" in url] return youtube_urls # 调用函数,你可以替换下面的 URL 为你需要的网址 url = 'https://wiki.gzher.com/doku.php?id=%E8%AF%AD%E8%A8%80:%E9%9F%B3%E4%B9%90' webpage_content = fetch_webpage(url) # 查找包含 "youtube.com" 的 URL youtube_urls = find_youtube_urls(webpage_content) print("Found YouTube URLs:") for url in youtube_urls: print(url)