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

No results found for query when using Screener #176

Open
sidward35 opened this issue Aug 7, 2023 · 5 comments
Open

No results found for query when using Screener #176

sidward35 opened this issue Aug 7, 2023 · 5 comments

Comments

@sidward35
Copy link
Contributor

My code:

from finviz.screener import Screener
import pandas as pd

stock_list = Screener(filters=['idx_sp500'], table='Overview')

Results in this error:

Traceback (most recent call last):
  File "venv/test.py", line 4, in <module>
    stock_list = Screener(filters=['idx_sp500'], table='Overview')
  File "venv/lib/python3.10/site-packages/finviz/screener.py", line 128, in __init__
    self.data = self.__search_screener()
  File "venv/lib/python3.10/site-packages/finviz/screener.py", line 437, in __search_screener
    self._rows = self.__check_rows()
  File "venv/lib/python3.10/site-packages/finviz/screener.py", line 407, in __check_rows
    raise NoResults(self._url.split("?")[1])
finviz.helper_functions.error_handling.NoResults: No results found for query: v=111&t=&f=idx_sp500&o=&s=&c=

It says No results found for query: v=111&t=&f=idx_sp500&o=&s=&c=, but going to https://finviz.com/screener.ashx?v=111&t=&f=idx_sp500&o=&s=&c= you can see the query works fine. Not sure what's causing it to believe no results were found.

@tonyz80
Copy link

tonyz80 commented Aug 7, 2023

I too am seeing the same error, i.e. nothing is returned.
I have tried many filters, and the response is the same: "No results found for query".

@RichardBoreiko
Copy link

RichardBoreiko commented Aug 8, 2023

Same here - it worked last week, but I'm getting zero rows from the screener today for several sets of criteria.

This line no longer works - it looks like they changed the width to 100%. It's harder to find a good selector now.
total_element = page_content.cssselect('td[width="128"]')

@sidward35 sidward35 changed the title No results found for query when using Screener with filter 'idx_sp500' No results found for query when using Screener Aug 8, 2023
@sidward35
Copy link
Contributor Author

sidward35 commented Aug 8, 2023

Got it working by changing the CSS selector from td[width="128"] to div[id="screener-total"] in finviz/helper_functions/scraper_functions.py on line 44

@RichardBoreiko
Copy link

RichardBoreiko commented Aug 8, 2023

I tried that, still not working.

total_element = page_content.cssselect('div[id="screener-total"]')

Update: I found that when combined with the fix for #166 in screener.py it started working. Both changes are needed to make this work.
` def __get_table_headers(self):
""" Private function used to return table headers. """

    headers = self._page_content.cssselect(
        'tr[valign="middle"]')[0].xpath("td//text()")
    # remove \r\n in headers
    return list(filter(lambda x: x.strip(), headers))`

@AGG2017
Copy link

AGG2017 commented Aug 12, 2023

My final more universal version that works at the moment:

def get_total_rows(page_content):
    """ Returns the total number of rows(results). """

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants