Skip to content

Instantly share code, notes, and snippets.

@colematt
Last active March 29, 2023 18:04
Show Gist options
  • Select an option

  • Save colematt/3ccba2918f245b81efbec17132deed3e to your computer and use it in GitHub Desktop.

Select an option

Save colematt/3ccba2918f245b81efbec17132deed3e to your computer and use it in GitHub Desktop.
Download a wordlist file from a remote server.
#!/usr/bin/python3
import urllib.request
from urllib.error import URLError
from string import whitespace
# Fetch a wordlist
try:
data = urllib.request.urlopen("https://raw.githubusercontent.com/colematt/english-words/master/words_alpha.txt")
wordlist = list(word.decode("utf-8").lower().rstrip(whitespace) for word in data.readlines())
except URLError as e:
print("Couldn't reach the dictionary server. Reason: %s" % e.reason)
raise(e)
except HTTPError as e:
print("The dictionary server couldn't fulfill the request. Error code: %s" % e.code)
raise(e)
except Exception as e:
print("Something else went wrong.")
raise(e)
finally:
print("Loaded the dictionary. Found %i words." % len(wordlist))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment