2 # Extract Latin famous phrases from wikipedia
5 from bs4 import BeautifulSoup
10 url = 'https://en.wikipedia.org/wiki/List_of_Latin_phrases_(full)'
11 response = requests.get(url)
12 html = response.content
14 soup = BeautifulSoup(html, "html.parser")
15 list_table = soup.find_all("table", attrs={"class":"wikitable"})
16 with open('phrases.csv', 'w') as f:
17 writer = csv.writer(f)
19 i = 0 # For the phrase id
20 # iterate through the tables in the page
21 for table in list_table:
22 for row in table.find_all("tr")[1:]:
23 cell = row.find_all("td")
29 # avoid out of bounds errors
36 for j in range (0, lan):
38 text=(content.get_text()).rstrip()
41 # append length of phrase
42 rowc.append(len(rowc[1]))
48 with open('phrases.csv', 'r+') as f:
51 f.writelines(line for line in lines if line.strip())
55 if __name__ == "__main__":