oscar0812 / pyfinviz

A python package to scrape data from finviz.com
Other
37 stars 8 forks source link

Screener returning empty dataframes #20

Closed ishanasse closed 11 months ago

ishanasse commented 11 months ago

I cannot use Screener as tried below; empty data frames are returned. Python: 3.10, pyfinviz==0.14

USE-CASE:

from pyfinviz.screener import Screener screener = Screener() options = [Screener.IndustryOption.STOCKS_ONLY_EX_FUNDS, Screener.AnalystRecomOption.STRONG_BUY_1] screener = Screener(filter_options=options, view_option=Screener.ViewOption.OVERVIEW, pages=[x for x in range(1, 4)]) print(screener.data_frames) # table information in a pd.DataFrame object per page {1: table_df, 2, table_df, ...}

OUTPUT:

{1: Empty DataFrame Columns: [] Index: [], 2: Empty DataFrame Columns: [] Index: [], 3: Empty DataFrame Columns: [] Index: []}

andy60 commented 11 months ago

Hi, i confirm this error. Have you suggestions?

oscar0812 commented 11 months ago

Working on it. Finviz changed UI elements.

oscar0812 commented 11 months ago

Issue is fixed. Please update to the latest version and confirm: pip install pyfinviz==0.15 I will close this issue once I receive confirmation. Thanks!

ishanasse commented 11 months ago

Thanks. I confirm it works again. This can be closed.

andy60 commented 11 months ago

With version 0.15, your example code:

from pyfinviz.groups import Groups

# with no params (sector overview)
groups = Groups()
# with params (View the group VALUATION of the INDUSTRY sector)
groups = Groups(group_option=Groups.GroupOption.INDUSTRY, view_option=Groups.ViewOption.VALUATION)
# with params (View the group PERFORMANCE of the TECH sector)
groups = Groups(group_option=Groups.GroupOption.INDUSTRY_TECHNOLOGY,
                view_option=Groups.ViewOption.PERFORMANCE)

# available variables:
print(groups.main_url)  # scraped URL
print(groups.soup)  # beautiful soup object
print(groups.table_df)  # table information in a pd.DataFrame object

gives me error:

AttributeError                            Traceback (most recent call last)
Cell In[2], line 4
      1 from pyfinviz.groups import Groups
      3 # with no params (sector overview)
----> 4 groups = Groups()
      5 # with params (View the group VALUATION of the INDUSTRY sector)
      6 groups = Groups(group_option=Groups.GroupOption.INDUSTRY, view_option=Groups.ViewOption.VALUATION)

File ~\anaconda3\lib\site-packages\pyfinviz\groups.py:32, in Groups.__init__(self, group_option, view_option)
     29 def __init__(self, group_option: GroupOption = GroupOption.SECTOR,
     30              view_option: ViewOption = ViewOption.OVERVIEW):
     31     self.main_url = 'https://finviz.com/groups.ashx?' + group_option.value + '&v=' + view_option.value
---> 32     self.soup, self.table_df = WebScraper.get_single_table_pandas(self.main_url)

File ~\anaconda3\lib\site-packages\pyfinviz\utils.py:49, in WebScraper.get_single_table_pandas(main_url)
     47 soup = WebScraper.get_soup(main_url)
     48 td = soup.find("td", {"class": "table-top"})
---> 49 main_table_rows = td.find_parent("table").find_all("tr")
     50 table_header = [re.sub(r'[^a-zA-Z0-9]', '', td.text.strip()) for td in
     51                 main_table_rows[0].find_all("td", recursive=False)]
     53 table_info_arr = [[td.text.strip() for td in row.find_all("td", recursive=False)] for row in
     54                   main_table_rows[1:]]

AttributeError: 'NoneType' object has no attribute 'find_parent'