Skip to content

Instantly share code, notes, and snippets.

View aleenprd's full-sized avatar
:octocat:
busy bee

Alin Preda aleenprd

:octocat:
busy bee
  • Group One
  • Copenhagen, Denmark
  • 01:55 (UTC -12:00)
  • LinkedIn in/alin-preda
View GitHub Profile
@aleenprd
aleenprd / fetch_el_if_available.py
Last active October 20, 2022 18:55
fetch_el_if_available
from typing import Union
def fetch_el_if_available(soup: BeautifulSoup, element_type: str, class_type: str) -> Union[str, None]:
"""Returns element text if found, otherwise returns None.
Args:
soup (BeautifulSoup): a b24 soup.
element_type (str): HTML type e.g. 'div'.
class_type (str): the class of the desired element.
@aleenprd
aleenprd / get_ratings_and_reviews_page.py
Last active October 20, 2022 18:12
Get Ratings and Reviews Page
def get_ratings_page(episode_page: str, suffix: str="/ratings/?ref_=tt_ov_rt"):
return ("/").join(episode_page.split("/")[:-1]) + suffix
def get_reviews_page(episode_page: str, suffix: str="/reviews?ref_=tt_urv"):
return ("/").join(episode_page.split("/")[:-1]) + suffix
@aleenprd
aleenprd / get_episodes_links.py
Created October 20, 2022 18:07
Get Links to Episodes
@aleenprd
aleenprd / imports_imdb_scraping.py
Last active October 20, 2022 18:53
IMDB Scraper Imports
# Data manipulation
import pandas as pd
import re as regex
# Scraping
import requests
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
@aleenprd
aleenprd / make_soup_with_selenium.py
Created October 20, 2022 17:59
Make Soup with Selenium
import requests
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
def make_soup_with_selenium(url: str, driver_service: Service) -> BeautifulSoup:
"""Return an HTML body from an URL.
@aleenprd
aleenprd / timing_function.py
Last active October 20, 2022 17:40
timing_decorator
from time import time
def timing(f: Callable) -> None:
"""Times a function runtime in minutes.
Args:
f (callable): a function/method.
"""
def wrap(*args, **kw):
ts = time()