Skip to content

Commit

Permalink
Merge pull request #180 from c4road/fix-get-total-rows
Browse files Browse the repository at this point in the history
Fix get_total_rows
  • Loading branch information
mariostoev authored Aug 21, 2023
2 parents ac00fcf + ed4286f commit 35cfe15
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 827 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
finviz/filters.json
finviz-platform.code-workspace
BACKLOG.md
NOTES.md
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
21 changes: 10 additions & 11 deletions finviz/helper_functions/scraper_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,16 @@ def get_table(page_html: requests.Response, headers, rows=None, **kwargs):
def get_total_rows(page_content):
""" Returns the total number of rows(results). """

total_element = page_content.cssselect('td[width="128"]')
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
options=[('class="count-text whitespace-nowrap">#1 / ',' Total</div>'),('class="count-text">#1 / ',' Total</td>')]
page_text = str(html.tostring(page_content))
for option_beg,option_end in options:
if option_beg in page_text:
total_number = page_text.split(option_beg)[1].split(option_end)[0]
try:
return int(total_number)
except ValueError:
return 0
return 0


def get_page_urls(page_content, rows, url):
Expand Down
Loading

0 comments on commit 35cfe15

Please sign in to comment.