38 lines
1.0 KiB
Python
Executable File
38 lines
1.0 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import requests, bs4, time
|
|
|
|
def get_titles(filename, title_type, maxrank):
|
|
with open(filename, "w", encoding="UTF-8") as file:
|
|
limit = 0
|
|
written = 0
|
|
|
|
while True:
|
|
page = requests.get("https://myanimelist.net/topanime.php?type=" + title_type + "&limit=" + str(limit), headers = {'User-agent': 'stopblockingmyscriptlol'})
|
|
page.raise_for_status()
|
|
|
|
soup = bs4.BeautifulSoup(page.text, "html.parser")
|
|
|
|
titles = soup.select("a[rel]")
|
|
|
|
for title in titles:
|
|
if len(title.text) == 2 or title.text == "Login":
|
|
continue
|
|
|
|
file.write(title.text.strip() + '\n')
|
|
written += 1
|
|
|
|
print(str(written), title.text.strip())
|
|
|
|
if written >= maxrank:
|
|
break
|
|
|
|
if written >= maxrank:
|
|
break
|
|
|
|
limit += 50
|
|
|
|
get_titles("rating.txt", "tv", 1750)
|
|
get_titles("movies.txt", "movie", 300)
|