]> git.armaanb.net Git - phrases.git/blob - extract.py
update formatting and convinience
[phrases.git] / extract.py
1 #!/usr/bin/env python3
2 # Extract Latin famous phrases from wikipedia
3 # Armaan Bhojwani 2020
4
5 from bs4 import BeautifulSoup
6 import requests
7
8 url = 'https://en.wikipedia.org/wiki/List_of_Latin_phrases_(full)'
9 response = requests.get(url)
10 html = response.content
11
12 soup = BeautifulSoup(html, "html.parser")
13 list_table = soup.find_all("table", attrs={"class":"wikitable"})
14 f = open("phrases", "w")
15
16 for table in list_table:
17     for row in table.find_all("tr")[1:]:
18         f.write("%" )
19         cell = row.find_all("td")
20         for content in cell:
21             text = content.get_text()
22             f.write("\n" + text)
23 f.close()