lit26 / finvizfinance

Finviz analysis python library.
https://finvizfinance.readthedocs.io/en/latest/
MIT License
450 stars 74 forks source link

BUG: Screen Does't work !!!! #90

Closed mmgarcia closed 11 months ago

mmgarcia commented 11 months ago

finvizfinance version checks

Reproducible Example

from finvizfinance.screener.overview import Overview
foverview = Overview()
filters_dict = {'Index': 'S&P 500', 'Sector': 'Basic Materials'}
foverview.set_filter(filters_dict=filters_dict)
df = foverview.screener_view()
df.head()

Error
cgptenv/lib/python3.11/site-packages/finvizfinance/screener/overview.py", line 280, in screener_view
    rows = table.findAll("tr")
           ^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'findAll'

Issue Description

the error is because table with class name "table-light" does not exist on dark mode

table = soup.find("table", class_="table-light")

Expected Behavior

return a list of tickers

Installed Versions

Replace this line with the output of finvizfinance.__version__ finvizfinance-0.14.6
Mauriciopc92 commented 11 months ago

Hi @mmgarcia, I noticed that this error with "findAll" method is due to an BeautifulSoup update, they changed some methods. for example: "findAll" became "find_all". You can check it here: https://beautiful-soup-4.readthedocs.io/en/latest/index.html?highlight=find#id18 I tried to fix the Overview.py by changing these methods, so far I have not been successful. I just sent an email to the developer, wish he can help us! See you!

lit26 commented 11 months ago

I will check beautiful soup lib.

Mauriciopc92 commented 11 months ago

I will check beautiful soup lib.

Thank you so much! I downloaded via zip file and replaced the files in the folders and it worked fine.

johnjcadigan commented 11 months ago

@lit26 @Mauriciopc92 did you figure out how to fix this one? I'm not tracking on the fix yet .

I have the same issue with screeners, both the "Overview" screener and the "Ownership" screener I have tried so far with the same error that was described above. Seems like soup does not find a table with "table-light" class and can confirm it when I print out and search in the HTML result that comes from soup.

I'm running conda environment with python3.7, finvizfinance 0.14.6, and tried upgrading beautifulsoup4 from 4.11.1 to 4.12.2 version.

lit26 commented 11 months ago

So the issue comes from the beautifulsoup lib. I am still working on that. You can downgrade that lib for now.

hieuimba commented 11 months ago

please let us know how it goes, really appreciate the effort!

johnjcadigan commented 11 months ago

@lit26 I tried to open a PR to suggest a fix for this one, but getting permission denied. Anyway, here's a screenshot of my diff to the "screener/overview.py" file, that seems to make this work for me:

image
johnjcadigan commented 11 months ago

@lit26 I tried to open a PR to suggest a fix for this one, but getting permission denied. Anyway, here's a screenshot of my diff to the "screener/overview.py" file, that seems to make this work for me:

image

PS I tried downgrading BS lib to a couple of the earlier 4 versions, but was still getting the same issue. It seems to not mind "findAll" vs. suggested new "find_all" syntax for whatever reason, but it's possible I could be overlooking something, too.

It seemed like the external finviz HTML might've changed that caused this issue, so just need to select the elements differently.