python - 使用 python 网页抓取下载 iframe 内容
问题描述
https://anime-world.in/?trembed=0&trid=1930&trtype=2这个链接只包含一个 iframe 标签,我想下载其中链接的视频。但是, src 属性将我带到一个无法访问的页面。我想知道我怎样才能下载视频。我已经尝试访问源站点(错误 403),并且我还尝试在网络面板中查找,在那里找不到任何东西。谢谢您的帮助!
解决方案
您可以使用此脚本如何从 URL 下载视频:
import re
import requests
from bs4 import BeautifulSoup
url = "https://anime-world.in/?trembed=0&trid=1930&trtype=2"
headers = {
"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0",
"Referer": "https://anime-world.in/",
}
with requests.session() as s:
soup = BeautifulSoup(s.get(url, headers=headers).content, "html.parser")
url2 = soup.iframe["src"]
html_doc = s.get(url2, headers=headers).text
link = re.search(r'file:".*?(http[^",]+)', html_doc).group(1)
print(link)
with open("file.mp4", "wb") as f:
f.write(s.get(link, headers=headers, verify=False).content)
print("Done.")
这打印:
https://6-yt5mQW3xieQHnfPa.server1cdn.xyz/link/AWI165B50FD/360/bb55f30227f8db11dcd19fef59fd6e5f/?sid=f3439234305d48ff7424333b2ca2de77
Done.
并与视频一起保存file.mp4
(下载需要一点时间。)
推荐阅读
- sql - 如何检查我的 SQL 数组中的特定元素是否跟在另一个元素之后?
- gensim - Gensim Doc2Vec 模型根据数据集返回不同的余弦相似度
- c++ - c++中double const* const* X的解释
- git - 如何使用另一个 GitHub URL 更新 FETCH 和 PUSH
- python - 使用 Kmeans 可视化系外行星数据集群并执行统计
- python - CloudKitty在创建实例时没有显示价格,并在启动命令下触发ERROR信息
- python - 如何创建一个可以告诉我特定列是否具有 NaN 值的新列
- api - Flurry Reporting API 是否显示国家维度的保留?
- javascript - 如何使用 EJS 检查页面上是否存在元素 ID?
- amazon-web-services - 获取服务:AmazonIdentityManagement;状态码:400;错误代码:创建 Cloudformation 堆栈时的 MalformedPolicyDocument