Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.55 KB | None | 0 0
  1. import requests
  2. import re
  3. import urllib.parse
  4. from urllib.request import Request, urlopen
  5. from bs4 import BeautifulSoup
  6.  
  7. from requests.packages.urllib3.exceptions import InsecureRequestWarning
  8. requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
  9.  
  10.  
  11. class API:
  12.     def __init__(self):
  13.         self.url_base = 'https://horriblesubs.info/'
  14.  
  15.     def episode_url(self):
  16.         # Splits the name of the series and turns the spaces (' ') into
  17.         # dash '-'. This will make it possible to create a fitting string.
  18.         # Example. 'Boku no Hero Academia' transforms to
  19.         # 'boku-no-hero-academia/'
  20.         # The variable anime_series, will be changed for a JSON, CSV or
  21.         # something else.
  22.         anime_series = 'Boku no Hero Academia'
  23.         respons = '-'.join(anime_series.split())
  24.         self.series_url = respons.lower() + '/'
  25.  
  26.     # def single_anime_data(self):
  27.     #     self.Session = requests.Session()
  28.     #     data = self.Session.get(self.url_base + self.series_url, verify=False)
  29.     #     print(data.text)
  30.     def find_link(self):
  31.         html_url = self.url_base + self.series_url + '#78'
  32.         print(html_url)
  33.         html_request = Request(html_url, headers={'User-Agent': 'Mozilla/5.0'})
  34.         html_page = urlopen(html_request).read()
  35.         soup = BeautifulSoup(html_page, features='lxml')
  36.         for link in soup.findAll('a', attrs={'href': re.compile("^https://")}):
  37.             print(link.get('href'))
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44. main = API()
  45. main.episode_url()
  46. #main.single_anime_data()
  47. main.find_link()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement