【问题标题】:How can I grab the src within this iframe using BeautifulSoup?如何使用 BeautifulSoup 在这个 iframe 中获取 src?
【发布时间】:2020-09-14 01:35:40
【问题描述】:

这是 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,“附加信息”代码可以复制/粘贴。 (也可以在整个 html 脚本的最后添加print(soup.prettify())

【问题讨论】:

    标签: python selenium-webdriver firefox iframe beautifulsoup


    【解决方案1】:

    解决方案: (soup.find("iframe")["src"]

    就我而言:print((soup.find("iframe"))["src"])

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多