|
#Created by davFaithid on Sunday 5/31/2020 |
|
#Please credit me if you use this in another project |
|
#Thank you |
|
|
|
import sys, os, time |
|
from urllib.request import urlopen, urlretrieve, Request |
|
import re |
|
from bs4 import BeautifulSoup |
|
url = str(sys.argv[1]).strip() |
|
req = Request( |
|
url, |
|
data=None, |
|
headers={ |
|
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:76.0) Gecko/20100101 Firefox/76.0' |
|
} |
|
) |
|
|
|
html_page = urlopen(req) |
|
soup = BeautifulSoup(html_page, features="html.parser") |
|
details = str(soup.find("div", {"class":"DetailEntityMasthead__tags"}).text) |
|
description = str(soup.find("p", {"class":"DetailEntityMasthead__description"}).text) |
|
#name = str(soup.find("img", {"role":"presentation"}).get("alt")) |
|
try: |
|
name = str(soup.find("span", {"class":"DetailEntityMasthead__title__text"}).text) |
|
except AttributeError: |
|
name = "Name is unavailable" |
|
print(""" |
|
Title: """,name,""" |
|
Details: """,details,""" |
|
Description: |
|
"""+description,""" |
|
""") |
|
name = re.sub('[^A-Za-z0-9 ]+', '', name) |
|
""" |
|
Need to find how to get background |
|
print("Downloading background @",burl) |
|
background = str(str(name) + "-landscape.jpeg") |
|
urlretrieve(burl, background) |
|
""" |
|
poster = str(str(name) + "-poster.jpeg") |
|
purl = soup.find("img", {"class":"DetailEntityMasthead__vertical-tile-img"}).get("src") |
|
print("Downloading poster @",purl) |
|
urlretrieve(purl, poster) |
|
logo = str(str(name) + "-logo.png") |
|
try: |
|
lurl = soup.find("img", {"role":"presentation","srcset":re.compile('&size=690x138|max&format=png 2x')}).get("src") |
|
print("Downloading logo @",lurl) |
|
urlretrieve(lurl, logo) |
|
except AttributeError: |
|
print("Logo not available") |
|
""" |
|
###This also works =) |
|
script = soup.find("script", {"type":"application/ld+json"}) |
|
print(script) |
|
if script: |
|
import json |
|
jsondata = json.loads(script.text) |
|
url2 = jsondata["image"] |
|
urlretrieve(url2, 'pic.jpg') |
|
""" |
Example: