Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update methods to extract title + add a workaround to render special chars #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions quizlet-dl.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ def scrapeSet(driver): #Scrape a single set of cards
saveCards(terms, definitions, driver)

def saveCards(terms, definitions, driver):
title = driver.find_element_by_xpath('/html/body/div[3]/div[2]/div[1]/div[2]/div/div[1]/div[1]/div/div/div[1]/h1').text
# new method to extract title
title = driver.find_elements_by_class_name('UIHeading--one')[0].text
user = driver.find_element_by_class_name('UserLink-username').text
id_ = driver.current_url.split('/')[-3]

Expand Down Expand Up @@ -113,9 +114,17 @@ def saveCards(terms, definitions, driver):
input('Press enter to exit...')
sys.exit()

with open(jsondir+title+' - '+id_+'.json', 'w+') as fp:
pathFile = jsondir+title+' - '+id_+'.json'
with open(pathFile, 'w+') as fp:
json.dump(data, fp, sort_keys=True, indent=4)

# This render special characters (like the IPA ð) instead of having unicode string (like "\u00f0"): it's not efficient but couldn't find a way to do it directly when extracting the cards or on the "data" var
with open(pathFile) as content_file:
content = content_file.read()
content = content.encode().decode('unicode-escape').encode("utf8")
with open(pathFile, "wb") as text_file:
text_file.write(content)

def main():
try:
opts = Options()
Expand Down