Advertisement
amaimon02

scrape_g1novelas

Feb 2nd, 2020
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.08 KB | None | 0 0
  1. import requests
  2. import webbrowser
  3. import youtube_dl
  4. from pprint import pprint
  5.  
  6.  
  7. def get_daily(url):
  8.     global ydl
  9.     ydl = youtube_dl.YoutubeDL({'outtmpl': '%(id)s%(ext)s'})
  10.  
  11.     with ydl:
  12.         result = ydl.extract_info(
  13.         url,
  14.         download=False
  15.         )
  16.  
  17.     if 'entries' in result:
  18.         video = result['entries'][0]
  19.     else:
  20.         video = result
  21.  
  22.     video_url = video['url']
  23.     return video_url
  24.  
  25.  
  26. def scrape(url):
  27.     var = requests.get(url)
  28.     spl = var.text.split("'")
  29.     link = [x for x in spl if x.find("clip") != -1 or x.find("dailymotion") != -1]
  30.  
  31.     link = link[0]
  32.     if "clip" in link:
  33.         var = requests.get(link).text
  34.         spl = var.split('"')
  35.         link_final = [x for x in spl if "mp4" in x][0]
  36.    
  37.     if "daily" in link:
  38.         link_final = get_daily(link)
  39.    
  40.  
  41.     html = f"""<video width="640" height="480" controls>
  42.       <source src="{link_final}" type="video/mp4">
  43.       <source src="{link_final}" type="video/ogg">
  44.     Your browser does not support the video tag.
  45.     </video>
  46.     """
  47.  
  48.     arquivo = open("html.html", "w")
  49.     arquivo.write(html)
  50.     arquivo.close()
  51.  
  52.     webbrowser.open("html.html", new=2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement