简体   繁体   中英

Can't get src from iframe with beautifulSoup python

I'm trying to extract video from a web page with BeautifulSoup in python but i got into some problems.

When i go to the web page and inspect to see html elements I see this tag

<iframe id="iframe-embed2" src="https://player.voxzer.org/view/1167612b04f6855ecc4bb5e0" allowfullscreen="true" webkitallowfullscreen="true" mozallowfullscreen="true" width="100%" height="auto" frameborder="0"></iframe>

and when i copy the src and open it, it shows me the video.

but when I use BeautifulSoup to find the iframe from the web page I got src as empty string.

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>]

What is the problem here?

this question doesn't have any working solutions

Parse iframe with blank src using bs4

What is the problem here?

I looked at site.text and found https://player.voxzer.org/view/1167612b04f6855ecc4bb5e0 to be placed in line

mainvideos.push('https://player.voxzer.org/view/1167612b04f6855ecc4bb5e0')

as .push is JavaScript method, apparently src of this iframe is set by JavaScript code, so you will need way to execute JavaScript code of site (for example using Selenium).

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