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, lineterminator="\n")
19 i = 0 # For the phrase id
22 headers = ['id', 'Latin', 'English', 'Notes', 'Length']
23 writer.writerow(headers)
25 # iterate through the tables in the page
26 for table in list_table:
27 for row in table.tbody.find_all("tr", recursive=False):
28 cell = row.find_all("td", recursive=False)
31 rowc.append(i) # append phrase id
35 text = (content.get_text(" ", strip=True)).rstrip()
39 rowc.append(len(rowc[1]))
44 if __name__ == "__main__":