Skip to content

Instantly share code, notes, and snippets.

@NiklasEi
Created August 29, 2018 15:50
Show Gist options
  • Save NiklasEi/b8198f6d1512e2bca5683a1f96ba0449 to your computer and use it in GitHub Desktop.
Save NiklasEi/b8198f6d1512e2bca5683a1f96ba0449 to your computer and use it in GitHub Desktop.
Lösung FAZ Sommerrätsel 2018
from bs4 import BeautifulSoup
from string import ascii_uppercase
from collections import Counter
import requests
def get_page(url):
names = []
req = requests.get(url)
if not (req.status_code == 200):
return False
soup = BeautifulSoup(req.text, "html5lib")
name_list = soup.ul
for li in name_list.children:
if li is None or li.find('a') is -1:
continue
a = li.find('a')
if a is None:
continue
names.append(a.text)
return names
def contains(name_to_check):
check = Counter("oftareamormobl")
for char in name_to_check:
count = check[char]
if not count:
return False
if count == 1:
del check[char]
else:
check[char] = count - 1
return True
url_general = 'https://en.wikipedia.org/wiki/List_of_painters_by_name_beginning_with_"{}"'
for c in ascii_uppercase:
for name in get_page(url_general.replace("{}", c)):
if len(name) > 14:
continue
if len(name) < 12:
continue
if contains(name.lower().replace(" ", "")):
print(name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment