Answer the question
In order to leave comments, you need to log in
How to parse video links from iframe tag using python?
there are sites with movies from which I wanted to parse temporary links to video files. The problem is that these links are in the iframe tag, and if they are pulled from the site, they simply do not work, in most cases, when you click on them, something like "movie not found" is displayed.
How to get working links?
I used firefox webdriver
driver.switch_to.frame(driver.find_element_by_tag_name("iframe"))
element2 = driver.find_element(By.XPATH, """/html/body/div[3]/div/div[2]/main/div[2]/div/article/div[1]/div[2]/div[3]/iframe""")
Answer the question
In order to leave comments, you need to log in
I don't think you are looking there. The site provides the ability to download videos, even without a player 1/2.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from bs4 import BeautifulSoup as bs
from fake_useragent import UserAgent as usr
import requests
import re
def get_video(url):
ua = usr(cache=True)
hdr = {
'accept': '*/*',
'user-agent': ua.chrome
}
try:
resp = requests.get(url=url, headers=hdr)
sp = bs(resp.text, 'lxml')
video = sp.find(re.compile('iframe'), id='cdn-player')
.find('div', id='qplayer').find('div', id='qplayer_vbox')
.find('div', id='qplayer_controls').find('div', id='qplayer_download_control')
.find('div', class_='qp_down_nav').find(re.compile('^a')).get('href');
req = requests.get(video, headers=hdr, stream=True)
with open('video.mp4', 'wb') as file:
for chunk in req.iter_content(8192):
file.write(chunk)
except Exception as ex:
return 'Upps... Check the URL please!'
def main():
get_video('https://kinogo.biz/28467-hobbit-nezhdannoe-puteshestvie-2012.html')
if __name__ == '__main__':
main()
loaded via driver, saved all code then processed it via bs4
html = browser.page_source
with open('1.html', 'w') as f:
f.write(html)
soup = BeautifulSoup(html, 'lxml')
iframe = soup.find('iframe', id="cdn-player").get('data-src')
//red.uboost.one/start/d3894e13ac7867f0ea0db534fb9762fd/b22f104beb331c4c67ca73d4c4d6bd9a
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question