mariostoev / finviz

Unofficial API for finviz.com
MIT License
1.05k stars 276 forks source link

Screener data and headers are empty #191

Open NirAbramovich opened 11 months ago

NirAbramovich commented 11 months ago

Finviz changed in the last days their screener table and now the headers of the table are in <th> instead of <td>, which makes the data and the headers of Screener class to be empty after constructing.

Before: <td class="table-top cursor-pointer" align="right" onclick="window.location='screener.ashx?v=111'">No.</td> After: <th class="table-header cursor-pointer" align="right" onclick="window.location='screener.ashx?v=111'">No.</th>

wfoor commented 11 months ago

I have the same issue, thank you for identifying the cause.

sidward35 commented 11 months ago

Replacing all instances of td with th in finviz/screener.py fixed it for me.

josyjr25 commented 11 months ago

I changed all th to th, but now I am getting this error in my program: KeyError Traceback (most recent call last) Cell In[1], line 38 28 filters = [ 29 "fa_debteq_u1", 30 "fa_roe_o10", (...) 34 "ta_sma50_pa&ft=4" 35 ] 36 stock_list = Screener(filters=filters, table="Performance") ---> 38 print(stock_list) 41 # Monthly, Candles, Large, No Technical Analysis 42 if valperiod == "d":

File ~\anaconda3\lib\site-packages\finviz\screener.py:182, in Screener.str(self) 179 table_list = [self.headers] 181 for row in self.data: --> 182 table_list.append([row[col] or "" for col in self.headers]) 184 return create_table_string(table_list)

File ~\anaconda3\lib\site-packages\finviz\screener.py:182, in (.0) 179 table_list = [self.headers] 181 for row in self.data: --> 182 table_list.append([row[col] or "" for col in self.headers]) 184 return create_table_string(table_list) KeyError´Change´

sunjingup commented 11 months ago

I have the same issue after change "td" to "th"

I changed all th to th, but now I am getting this error in my program: KeyError Traceback (most recent call last) Cell In[1], line 38 28 filters = [ 29 "fa_debteq_u1", 30 "fa_roe_o10", (...) 34 "ta_sma50_pa&ft=4" 35 ] 36 stock_list = Screener(filters=filters, table="Performance") ---> 38 print(stock_list) 41 # Monthly, Candles, Large, No Technical Analysis 42 if valperiod == "d":

File ~\anaconda3\lib\site-packages\finviz\screener.py:182, in Screener.str(self) 179 table_list = [self.headers] 181 for row in self.data: --> 182 table_list.append([row[col] or "" for col in self.headers]) 184 return create_table_string(table_list)

File ~\anaconda3\lib\site-packages\finviz\screener.py:182, in (.0) 179 table_list = [self.headers] 181 for row in self.data: --> 182 table_list.append([row[col] or "" for col in self.headers]) 184 return create_table_string(table_list) KeyError´Change´

PBbanana commented 11 months ago

I tried to trace back the issue. I think that the problem may be in line 254 of the Screener function:

th.get_text().strip() == "Exchange":

I think that the word "Exchange" is not present in bs.find_all("th"). This is what I get from that search:

for th in bs.find_all("th"): print(th)

No. Ticker Company Sector Industry Country Market Cap P/E Price Change Volume
PBbanana commented 11 months ago

Replacing all instances of td with th in finviz/screener.py fixed it for me.

This did NOT fix it for me. What fixed it was to replace 'td' with 'th' only in line 417 of screener.py (in function get_table_headers):

    header_elements = self._page_content.cssselect('tr[valign="middle"]')[0].xpath("td")
josyjr25 commented 11 months ago

Any solutions to the problem???

josyjr25 commented 11 months ago

Hi: Have you find a solution??? Regards, José

El vie, 6 oct 2023 a las 2:50, JJ @.***>) escribió:

I have the same issue with

I changed all th to th, but now I am getting this error in my program: KeyError Traceback (most recent call last) Cell In[1], line 38 28 filters = [ 29 "fa_debteq_u1", 30 "fa_roe_o10", (...) 34 "ta_sma50_pa&ft=4" 35 ] 36 stock_list = Screener(filters=filters, table="Performance") ---> 38 print(stock_list) 41 # Monthly, Candles, Large, No Technical Analysis 42 if valperiod == "d":

File ~\anaconda3\lib\site-packages\finviz\screener.py:182, in Screener. str(self) 179 table_list = [self.headers] 181 for row in self.data: --> 182 table_list.append([row[col] or "" for col in self.headers]) 184 return create_table_string(table_list)

File ~\anaconda3\lib\site-packages\finviz\screener.py:182, in (.0) 179 table_list = [self.headers] 181 for row in self.data: --> 182 table_list.append([row[col] or "" for col in self.headers]) 184 return create_table_string(table_list) KeyError´Change´

I have the issue above

— Reply to this email directly, view it on GitHub https://github.com/mariostoev/finviz/issues/191#issuecomment-1750220323, or unsubscribe https://github.com/notifications/unsubscribe-auth/AYXWWE35NCUOOCWNWCJBWD3X57A4JAVCNFSM6AAAAAA5NOEQGSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONJQGIZDAMZSGM . You are receiving this because you commented.Message ID: @.***>

jackomak commented 7 months ago

Replacing all instances of td with th in finviz/screener.py fixed it for me.

This did NOT fix it for me. What fixed it was to replace 'td' with 'th' only in line 417 of screener.py (in function get_table_headers):

    header_elements = self._page_content.cssselect('tr[valign="middle"]')[0].xpath("td")

this worked for me!