Grote push
This commit is contained in:
parent
4bcf82fa3e
commit
847f6650e9
7 changed files with 175 additions and 42 deletions
41
cgi-bin/stresstest.py
Normal file
41
cgi-bin/stresstest.py
Normal file
|
@ -0,0 +1,41 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
"""
|
||||
Dit script is enkel en alleen bedoeld om heel veel willekeurige pagina's te kunnen testen en
|
||||
enkel degene eruit te halen die falen (en dus niet correct afgehandeld worden).
|
||||
"""
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
import requests
|
||||
|
||||
from scraper import converteer, zoek_link
|
||||
|
||||
|
||||
def run(taal, start, stop):
|
||||
lijst = [converteer(start, True)] if start != 'Special:Random' else []
|
||||
base = f"https://{taal}.wikipedia.org/wiki/"
|
||||
|
||||
while start != stop:
|
||||
|
||||
# Dit is het enigste dat we aanpassen.
|
||||
print(lijst[-1] if len(lijst) != 0 else [])
|
||||
|
||||
pagina = requests.get(base + converteer(start, False))
|
||||
if pagina.status_code != 200:
|
||||
return {'error': f"Er ging iets fout bij het inladen van '{lijst[-1]}'. Bestaat de website?"}
|
||||
soep = BeautifulSoup(pagina.content, 'html.parser')
|
||||
start = converteer(zoek_link(soep))
|
||||
if start is None:
|
||||
return {'error': f"Er konden geen nieuwe links meer gevonden worden op '{lijst[-1]}'"}
|
||||
if start in lijst:
|
||||
return {'error':
|
||||
f"Cyclus gedetecteerd op '{start}', startende vanaf '{lijst[0]}'. Het onafgewerkte pad zal niet worden toegevoegd aan het overzicht. "
|
||||
}
|
||||
lijst.append(start)
|
||||
return {'pad': lijst}
|
||||
|
||||
|
||||
antwoord = run('en', 'Special:Random', 'Philosophy')
|
||||
while 'pad' in antwoord or antwoord['error'].startswith('Cyclus'):
|
||||
antwoord = run('en', 'Special:Random', 'Philosophy')
|
||||
print(antwoord['error'])
|
Reference in a new issue