Created
April 25, 2023 22:08
-
-
Save CodeByAidan/24d5653424bdcf86e570338171d2f016 to your computer and use it in GitHub Desktop.
Scrapes any description for https://codewars.com! Super light and simple. Python 3.8+
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests | |
| from bs4 import BeautifulSoup | |
| import re | |
| while True: | |
| user_url = input("Enter the URL: ") | |
| pattern = re.compile(r"https://www.codewars.com/kata/([^/?#]+)") | |
| if match := pattern.search(user_url): | |
| kata_id = match[1] | |
| url = f"https://www.codewars.com/api/v1/code-challenges/{kata_id}" | |
| response = requests.get(url) | |
| data = response.json() | |
| if 'description' in data: | |
| description_html = data['description'] | |
| soup = BeautifulSoup(description_html, "html.parser") | |
| description = soup.get_text(strip=True) | |
| print(description) | |
| break | |
| else: | |
| print("Invalid URL, please try again.") | |
| else: | |
| print("Invalid URL, please try again.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment