You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
804B

  1. import requests
  2. import os
  3. import wget
  4. from bs4 import BeautifulSoup
  5. class imgur():
  6. """Class for all interactions with Imgur"""
  7. def __init__(self):
  8. pass
  9. def removed(self,url):
  10. page = requests.get(url)
  11. soup = BeautifulSoup(page.content, 'html.parser')
  12. if "removed.png" in soup.a["src"]:
  13. return True
  14. else:
  15. return False
  16. def get(self, url):
  17. if self.removed(url):
  18. return False
  19. if url.split(".")[-1] in ("png", "jpg", "jpeg", "gif", "gifv"):
  20. return url
  21. elif url.split("/")[-2] == "a":
  22. page = requests.get(url)
  23. soup = BeautifulSoup(page.content, 'html.parser')
  24. list = []
  25. for img in soup.find_all("img"):
  26. if "imgur" in img["src"]:
  27. if not img["src"] in list:
  28. list.append(img["src"])
  29. if len(list) > 1:
  30. return False
  31. else:
  32. return list[0]