Skip to content

Instantly share code, notes, and snippets.

@pscollins
Last active January 3, 2016 13:19
Show Gist options
  • Select an option

  • Save pscollins/8469193 to your computer and use it in GitHub Desktop.

Select an option

Save pscollins/8469193 to your computer and use it in GitHub Desktop.
let's try again
import requests
from bs4 import BeautifulSoup
BASE_URL = "http://ordnet.dk/ddo/ordbog?query={}"
def main(path_to_file):
ans = []
words = [line.split(" ")[0] for line in open(path_to_file)]
for word in words:
soup = BeautifulSoup(requests.get(BASE_URL.format(word)).text)
try:
ans.append(soup.select(".lydskrift")[0].contents[1])
except IndexError:
pass
return ans
to_write = main("word_list.txt")
print to_write
open("wordlist_done.txt", "w").write("\n".join(to_write))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment