2024-05-12 13:05:33 发布
网友
我是Python新手,正在努力寻找解决方案或方法来完成以下工作。我需要从一个网站上获得两样东西,我可以从inspect元素中获得:指向.m3u8文件的链接,该文件可以在网站的html(元素选项卡)中找到,以及指向网络选项卡中的.ts文件的链接(不管是哪一个)。有人知道怎么做吗?提前谢谢
使用BS4和请求:
import requests from bs4 import BeautifulSoup URL = 'https://stackoverflow.com/questions/64828046/' page = requests.get(URL) soup = BeautifulSoup(page.content, 'html.parser') results = soup.find(id='question-header') print(results)
from urllib.request import urlopen import lxml.html connection = urlopen('http://yourwebsite') dom = lxml.html.fromstring(connection.read()) for link in dom.xpath('//a/@href'): if link.endswith(".m3u8") or link.endwith(".ts"): print(link)
您可以使用其他if conditions检查链接中是否有内容,如:
if conditions
if "m3u8" in link: print(link)
使用BS4和请求:
您可以使用其他
if conditions
检查链接中是否有内容,如:相关问题 更多 >
编程相关推荐