Skip to content

Instantly share code, notes, and snippets.

@AnasAlmasri
Created May 9, 2020 17:43
Show Gist options
  • Save AnasAlmasri/f5e2e9ea62ac1baddbf825e1027e19e5 to your computer and use it in GitHub Desktop.
Save AnasAlmasri/f5e2e9ea62ac1baddbf825e1027e19e5 to your computer and use it in GitHub Desktop.
current_year = 0
# loop through table rows retrieving the data and adding it to our stats dictionary
for row in stats_table.find_elements_by_tag_name('tr'):
if (len(row.get_attribute('class')) > 0):
if ('sortableTable-row--dateBucket' in row.get_attribute('class')): # when encountering a year row
for cell in row.find_elements_by_tag_name('td'):
current_year = cell.text
stats[current_year] = []
elif ('js-statsTableRow' in row.get_attribute('class')): # when encountering a story
td_idx = 1
story = {}
for cell in row.find_elements_by_tag_name('td'):
if td_idx == 1: story['title'] = cell.text
elif td_idx == 2: story['views'] = cell.find_elements_by_class_name('sortableTable-value')[0].get_attribute("innerHTML")
elif td_idx == 3: story['reads'] = cell.find_elements_by_class_name('sortableTable-value')[0].get_attribute("innerHTML")
elif td_idx == 4: story['ratio'] = cell.text
elif td_idx == 5: story['fans'] = cell.find_elements_by_class_name('sortableTable-value')[0].get_attribute("innerHTML")
td_idx += 1
stats[current_year].append(story)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment