Open NirAbramovich opened 11 months ago
I have the same issue, thank you for identifying the cause.
Replacing all instances of td
with th
in finviz/screener.py fixed it for me.
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
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´
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)
Replacing all instances of
td
withth
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")
Any solutions to the problem???
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: @.***>
Replacing all instances of
td
withth
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!
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>