Skip to content

Commit

Permalink
etym css upd8
Browse files Browse the repository at this point in the history
  • Loading branch information
treatmesubj committed Sep 6, 2023
1 parent 20a7bd1 commit b04d17d
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions thesr/thesr.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,14 @@ def get_syns_ants(word):
def get_etymology(word):
response = requests.get(f"https://www.etymonline.com/word/{word}")
soup = BeautifulSoup(response.text, "html.parser")
class_elems = soup.select("div[class^='word'] [class^='word__name']")
etym_elems = soup.select("div[class^='word'] [class^='word__def']")
class_elems = soup.select("div[class^='ant'] > div[class^='word'] [class^='word__name']")
etym_elems = soup.select("div[class^='ant'] > div[class^='word'] [class^='word__def']")
zipped_elems = zip(class_elems, etym_elems)
homonyms = []
for class_elem, etym_elem in zipped_elems:
if "href" not in class_elem.attrs.keys():
etym_text = ""
for etym_p_elem in etym_elem.select("p"):
etym_text += f"{etym_p_elem.text}\n"
homonyms.append(
{"etym_desc": etym_text.rstrip("\n"), "word_class": class_elem.text}
)
homonyms.append(
{"etym_desc": etym_elem.text.rstrip("\n"), "word_class": class_elem.text}
)
return homonyms


Expand Down

0 comments on commit b04d17d

Please sign in to comment.