简体   繁体   中英

How can I grab the src within this iframe using BeautifulSoup?

Here's the iframe:

<iframe allow="autoplay; fullscreen" allowfullscreen="yes" frameborder="no" scrolling="no" src="https://www.example.com" style="width: 100%; height: 100%;"></iframe>

My attempt:

print(soup.find("iframe")["src"])

Additional Info for this case:

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()

The 'Additional Info' code will work copy/paste if you want to find the exact html. (Could also add print(soup.prettify()) at the very end for the whole html script.

Solution: (soup.find("iframe")["src"]

In my case: print((soup.find("iframe"))["src"])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM