【发布时间】:2021-05-17 07:39:29
【问题描述】:
我正在尝试使用 Python 中的 BeautifulSoup 从网页中提取视频,但遇到了一些问题。
当我进入网页并检查 html 元素时,我看到了这个标签
<iframe id="iframe-embed2" src="https://player.voxzer.org/view/1167612b04f6855ecc4bb5e0" allowfullscreen="true" webkitallowfullscreen="true" mozallowfullscreen="true" width="100%" height="auto" frameborder="0"></iframe>
当我复制 src 并打开它时,它会显示视频。
但是当我使用 BeautifulSoup 从网页中查找 iframe 时,我将 src 作为空字符串。
import requests
from bs4 import BeautifulSoup
site = requests.get("the url ...")
soup = BeautifulSoup(site.text, "html.parser")
print(soup.find_all("iframe"))
>>> [<iframe allowfullscreen="true" frameborder="0" height="auto" id="iframe-embed2" mozallowfullscreen="true" scrolling="no" src="" webkitallowfullscreen="true" width="100%"></iframe>]
这里有什么问题?
这个问题没有任何可行的解决方案
【问题讨论】:
-
可以发网页吗?这样可以更轻松地重现您的问题。
-
@DSteman 好的,这是网页123moviesfree.net/season/silicon-valley-season-2-6026/…
-
请检查您获取的内容中是否设置了
src,即在site = requests... 行之后立即执行print('src="https://player.voxzer.org/view/1167612b04f6855ecc4bb5e0"' in site.text)并写入输出内容 -
@Daweo 它返回 True
标签: python python-3.x beautifulsoup python-requests