Last active
June 22, 2022 03:51
-
-
Save NaoY-2501/05ce373bb82d1e07b38f3eb65f7100d2 to your computer and use it in GitHub Desktop.
TIF2022 日別ラインナップ抽出スクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bs4 import BeautifulSoup as bs | |
import requests | |
URL = "https://official.idolfes.com/s/tif2022/page/lineup?ima=0210" | |
DAYS = { | |
"5日": "p-lineup_artist_data tif22-day1", | |
"6日": "p-lineup_artist_data tif22-day2", | |
"7日": "p-lineup_artist_data tif22-day3", | |
} | |
DAY1_2 = "p-lineup_artist_data tif22-day1_2" | |
DAY1_3 = "p-lineup_artist_data tif22-day1_3" | |
DAY2_3 = "p-lineup_artist_data tif22-day2_3" | |
def extract_lineup(soup, klass): | |
day1_groups = soup.find_all("div", class_=klass) | |
names = [ | |
g.find("div", class_="p-lineup_artist_data__name") | |
.find("div", class_="p-lineup_artist_data__name-text") | |
.text.strip() | |
for g in day1_groups | |
] | |
names = [name.split("\n")[0] for name in names] | |
return names | |
res = requests.get(URL) | |
content = res.content | |
soup = bs(content, "html.parser") | |
lineups = {} | |
for day, cls in DAYS.items(): | |
names = extract_lineup(soup, cls) | |
lineups[day] = names | |
names_day1_2 = extract_lineup(soup, DAY1_2) | |
lineups["5日"].extend(names_day1_2) | |
lineups["6日"].extend(names_day1_2) | |
names_day2_3 = extract_lineup(soup, DAY2_3) | |
lineups["6日"].extend(names_day2_3) | |
lineups["7日"].extend(names_day2_3) | |
names_day1_3 = extract_lineup(soup, DAY1_3) | |
lineups["5日"].extend(names_day1_3) | |
lineups["7日"].extend(names_day1_3) | |
with open("tif2022_lineup_by_day.md", "w") as fout: | |
for day in ["5日", "6日", "7日"]: | |
fout.write(f"## {day}\n") | |
for group in lineups[day]: | |
if group.startswith("#"): | |
group = f"\{group}" # 01familiaグループ対策 | |
elif group == "4864.": | |
group = "4864\." # Markdownで1..となる謎現象対策 | |
fout.write(f"- {group}\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment