(New feature) 0.5.1 - download posters and use them as icons.
This commit is contained in:
+24
-4
@@ -24,14 +24,25 @@ This module has all for simplify work with scraping.
|
||||
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
import os
|
||||
|
||||
class Scraper:
|
||||
"""The handler of web connection."""
|
||||
def __init__(self, HEADERS):
|
||||
def __init__(self, HEADERS, POSTER_PATH="posters"):
|
||||
"""Initialising the connection information."""
|
||||
self.HEADERS = HEADERS
|
||||
self.HEADERS, self.POSTER_PATH = HEADERS, POSTER_PATH
|
||||
self.mkdir(self.POSTER_PATH)
|
||||
|
||||
def get_anime(self, url):
|
||||
def mkdir(self, path):
|
||||
if not os.path.isdir(path):
|
||||
os.mkdir(path)
|
||||
|
||||
def file_exist(self, path):
|
||||
if os.path.isfile(path):
|
||||
return True
|
||||
return False
|
||||
|
||||
def get_anime(self, url, GETPOSTER = False):
|
||||
"""
|
||||
Return None if response is not 200.
|
||||
Otherwise, return [url, title, status].
|
||||
@@ -48,4 +59,13 @@ class Scraper:
|
||||
str_current = data.get_text()
|
||||
str_current = str_current[str_current.find(str_find)+len(str_find):]
|
||||
status = str_current[:str_current.find('\n')]
|
||||
return [url, title, status]
|
||||
# Poster
|
||||
poster_url = "https://anitube.in.ua" + soup.find('span', class_="story_post").find('img').get('src')
|
||||
poster_path = f"{self.POSTER_PATH}/{poster_url.split('/')[-1]}"
|
||||
if GETPOSTER and not self.file_exist(poster_path):
|
||||
print(f"[DONWLOADING] The poster for {title}")
|
||||
img = requests.get(poster_url)
|
||||
with open(poster_path,'wb') as file:
|
||||
file.write(img.content)
|
||||
print(f"[DONWLOADED] The poster for {title}")
|
||||
return [url, title, status, poster_path]
|
||||
|
||||
Reference in New Issue
Block a user