|
| 1 | + |
| 2 | + |
| 3 | +try: |
| 4 | + import requests |
| 5 | + from bs4 import BeautifulSoup |
| 6 | + import urllib.parse as parse |
| 7 | + import re |
| 8 | + import argparse |
| 9 | + |
| 10 | +except ImportError: |
| 11 | + print('Some modules are not installed! ') |
| 12 | + |
| 13 | +# mainly bs4 lib is used for extracting html from web pages |
| 14 | + |
| 15 | +def details(soup): |
| 16 | + |
| 17 | + info = soup.find('div', {'class': 'pure-1 md-3-5'}) # selecting div with class pure... |
| 18 | + print("\nAbout the Anime : \n", "\t\t", info.find('p').getText(), "\n") # now extracting the text for p tag of the div |
| 19 | + |
| 20 | + total_episodes = soup.find('div', {'class': 'pure-1 md-1-5'}) |
| 21 | + print("\nTotal number of episodes :\t", |
| 22 | + re.sub("[^0-9]", "", total_episodes.find('span').getText())) # usimg regex for only selecting numbers |
| 23 | + |
| 24 | + Active_years = soup.find('span', {'class': 'iconYear'}) |
| 25 | + print("\n Years Active (From-To)\t:\t", |
| 26 | + Active_years.getText(), "-\n") |
| 27 | + |
| 28 | + rating = soup.find('div', {'class': 'avgRating'}) |
| 29 | + print("Rating : ", rating.find('span').getText()) |
| 30 | + |
| 31 | + tags = soup.find('div', {'class': 'tags'}) |
| 32 | + # print("Tags : ", tags.find('ul').getText()) |
| 33 | + |
| 34 | + list = [] |
| 35 | + for _ in range(4): |
| 36 | + list.append(tags.find('ul').getText()) |
| 37 | + |
| 38 | + print("\nTags : \n") |
| 39 | + print((list[0].replace("\n", " "))) |
| 40 | + |
| 41 | + |
| 42 | +def entry(): |
| 43 | + print("\nType complete name>>\n") |
| 44 | + anime_name = input( |
| 45 | + "[+] Enter the name of the Anime : ").strip().title().replace(" ", "-") |
| 46 | + |
| 47 | + print("\n") |
| 48 | + print(anime_name) |
| 49 | + |
| 50 | + search_url = ("https://www.anime-planet.com/anime/" + anime_name) |
| 51 | + source_code = requests.get(search_url) |
| 52 | + content = source_code.content |
| 53 | + global soup |
| 54 | + soup = BeautifulSoup(content, features="html.parser") # to parse the selectd HTML |
| 55 | + # print(soup.prettify) |
| 56 | + |
| 57 | + try: |
| 58 | + details(soup) |
| 59 | + except AttributeError: |
| 60 | + print("Anime info not found") |
| 61 | + |
| 62 | + |
| 63 | +if __name__ == "__main__": |
| 64 | + entry() |
0 commit comments