Skip to content

Instantly share code, notes, and snippets.

@CodeByAidan
Created April 25, 2023 22:08
Show Gist options
  • Select an option

  • Save CodeByAidan/24d5653424bdcf86e570338171d2f016 to your computer and use it in GitHub Desktop.

Select an option

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+
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