It's a type of Planche
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

43 行
1.3KB

  1. #!/usr/bin/env python
  2. # Example of using BeautifulSoup4 to parse a site
  3. import os
  4. from time import sleep
  5. from urllib.parse import urlsplit
  6. import requests
  7. from bs4 import BeautifulSoup
  8. session = requests.Session()
  9. page_urls = [
  10. "https://slackmojis.com/categories/19-random-emojis",
  11. ]
  12. for _ in range(1, 34):
  13. page_urls.append(f"https://slackmojis.com/categories/19-random-emojis?page={_}")
  14. base_dir = "/mnt/tank/media/pictures/emojis/Random/"
  15. emoji_images = []
  16. for page_url in page_urls:
  17. emoji_page = session.get(page_url)
  18. emoji_page.raise_for_status()
  19. emoji_parsed = BeautifulSoup(emoji_page.text)
  20. for image_list in [_.find_all("img") for _ in emoji_parsed.find_all("li", "emoji")]:
  21. emoji_images.extend(image_list)
  22. sleep(1)
  23. for image_link in [_.get("src") for _ in emoji_images]:
  24. with session.get(image_link, stream=True) as request:
  25. filename = f"{base_dir}{os.path.basename(urlsplit(image_link).path)}"
  26. base_filename = ".".join(filename.split(".")[0:-1])
  27. file_ext = filename.split(".")[-1]
  28. dup_count = 1
  29. while os.path.exists(filename):
  30. filename = f"{base_filename}_{dup_count}.{file_ext}"
  31. dup_count += 1
  32. with open(filename, "wb") as f:
  33. for chunk in request.iter_content(chunk_size=8192):
  34. f.write(chunk)