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