from bs4 import BeautifulSoup import requests from typing import List class FembooruClient: def __init__(self): self.BASE_URL = "https://fembooru.jp" def parse_page(self, page: int) -> str: res = requests.get(f"{self.BASE_URL}/post/list/{page}") return BeautifulSoup(res.text, "html.parser") def get_random_tagline(self) -> str: soup = self.parse_page(1) tip = soup.find(id="tips") return tip.text def get_images(self, page: int) -> List[dict]: soup = self.parse_page(page) imgs = soup.find(id="image-list").find_all("img") imgs_map = map(lambda i: { "label": i.get("alt"), "thumb_url": self.BASE_URL + i.get("src") }, imgs) return list(imgs_map)