forked from avinashkranjan/Amazing-Python-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanime_tracker.py
68 lines (50 loc) · 1.86 KB
/
anime_tracker.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
try:
import requests
from bs4 import BeautifulSoup
import urllib.parse as parse
import re
import argparse
except ImportError:
print('Some modules are not installed! ')
# mainly bs4 lib is used for extracting html from web pages
def details(soup):
# selecting div with class pure...
info = soup.find('div', {'class': 'pure-1 md-3-5'})
# now extracting the text for p tag of the div
print("\nAbout the Anime : \n", "\t\t", info.find('p').getText(), "\n")
total_episodes = soup.find('div', {'class': 'pure-1 md-1-5'})
print("\nTotal number of episodes :\t",
re.sub(
"[^0-9]", "",
total_episodes.find(
'span').getText())) # usimg regex for only selecting numbers
Active_years = soup.find('span', {'class': 'iconYear'})
print("\n Years Active (From-To)\t:\t", Active_years.getText(), "-\n")
rating = soup.find('div', {'class': 'avgRating'})
print("Rating : ", rating.find('span').getText())
tags = soup.find('div', {'class': 'tags'})
# print("Tags : ", tags.find('ul').getText())
list = []
for _ in range(4):
list.append(tags.find('ul').getText())
print("\nTags : \n")
print((list[0].replace("\n", " ")))
def entry():
print("\nType complete name>>\n")
anime_name = input("Enter the name of the anime : ")
anime_name = (" ".join(anime_name.split())).title().replace(" ", "-")
print("\n")
print(anime_name)
search_url = ("https://www.anime-planet.com/anime/" + anime_name)
source_code = requests.get(search_url)
content = source_code.content
global soup
# to parse the selectd HTML
soup = BeautifulSoup(content, features="html.parser")
# print(soup.prettify)
try:
details(soup)
except AttributeError:
print("Anime info not found")
if __name__ == "__main__":
entry()