python - 如何使用 BeautifulSoup 在这个 iframe 中获取 src?
问题描述
这是 iframe:
<iframe allow="autoplay; fullscreen" allowfullscreen="yes" frameborder="no" scrolling="no" src="https://www.example.com" style="width: 100%; height: 100%;"></iframe>
我的尝试:
print(soup.find("iframe")["src"])
此案例的附加信息:
from selenium import webdriver
from bs4 import BeautifulSoup
import time
driver = webdriver.Firefox()
driver.get("https://9anime.to/watch/puella-magi-madoka-magica.q1n/yqq3r9x")
time.sleep(5)
soup = BeautifulSoup(driver.page_source, "lxml")
print(soup.find("iframe"))
driver.quit()
如果您想找到确切的 html,“附加信息”代码将复制/粘贴。(也可以print(soup.prettify())
在整个 html 脚本的最后添加。
解决方案
解决方案: (soup.find("iframe")["src"]
就我而言: print((soup.find("iframe"))["src"])
推荐阅读
- flutter - Flutter:未来的构建者不更新表单值
- python - 使用 pandas 从列中查找字符串
- reactjs - 映射嵌套在来自 API 的对象中的对象 | JSX 映射问题
- jquery - Ajax post 调用多次
- python - 为什么亚马逊 S3 客户端依赖于位置?
- node.js - PM2 无法获取 ~/.profile 文件中设置的更新值
- python - 基于 cumsum 从轮廓填充区域
- unit-testing - 使用 DI (injectable-getIt) 进行颤振测试的正确方法?
- powershell - 从 .pkgx 获取信息
- python - 具有真假条件的迭代次数