-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetAnimesMyAnimeList.py
More file actions
49 lines (42 loc) · 1.67 KB
/
Copy pathgetAnimesMyAnimeList.py
File metadata and controls
49 lines (42 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import random
import requests
from bs4 import BeautifulSoup
url = 'https://myanimelist.net/topanime.php'
def getAnime(url):
response = requests.get(url)
html = response.text
soup = BeautifulSoup(html, 'html.parser')
animeNameTags = soup.select('h3.anime_ranking_h3')
animeHref = soup.select('h3.anime_ranking_h3 a')
length = len(animeNameTags)
randNum = random.randrange(0, length)
animeEpisodes = soup.select('div.information')
animeEpisodeFilter = animeEpisodes[randNum].text
animeEpisode = animeEpisodeFilter.split('\n')[1]
newUrl = animeHref[randNum]['href']
getAnimeInfo(newUrl, animeEpisode)
def getAnimeInfo(newUrl, animeEpisode):
response = requests.get(newUrl)
html = response.text
soup = BeautifulSoup(html, 'html.parser')
animeNameTag = soup.select('title')
animeName = animeNameTag[0].text.split(' - ')[0]
getGenre = soup.find_all(text='Genres:')[0]
animeGenreAux = getGenre.parent # .parent
animeGenre = animeGenreAux.find_all('a')
animeGenreList = []
for genre in animeGenre:
animeGenreList.append(genre.text)
animeGenreString = 'Genres: (' + ', '.join(animeGenreList) + ')'
getSynopsis = soup.find('p', itemprop='description').text.split('[Written by MAL Rewrite]')[0]
print(f'-------------------------------------\nKATIAAAAAAU GERANDO ANIME KATIAAAAAAU\n{animeName} \n{animeEpisode}\n{animeGenreString}\n---Synopsis---\n{getSynopsis}')
def main():
getAnime(url)
while(True):
answer = input('________________________\nAnother one? (y/n) ')
if answer != 'y':
break
else:
getAnime(url)
if __name__ == '__main__':
main()