Skip to content

Commit

Permalink
fixing get_total_rows to correctly fetch the table data and not get l…
Browse files Browse the repository at this point in the history
…ist index out of range errors (mariostoev#163)
  • Loading branch information
Fachastorm authored Apr 19, 2023
1 parent 7ac6fcc commit ba6c092
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions finviz/helper_functions/scraper_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ def get_total_rows(page_content):
""" Returns the total number of rows(results). """

total_element = page_content.cssselect('td[width="128"]')
total_number = (
etree.tostring(total_element[0]).decode("utf-8").split("</b>")[1].split()[0]
)

try:
return int(total_number)
except ValueError:
if len(total_element) > 0:
content = etree.tostring(total_element[0]).decode("utf-8")
total_number = content.split("/")[1].split()[0]

try:
return int(total_number)
except ValueError:
return 0
else:
return 0


Expand Down

0 comments on commit ba6c092

Please sign in to comment.