mariostoev/finviz

Screener data and headers are empty

Opened this issue · 9 comments

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>

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 (.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 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)

No. Ticker Company Sector Industry Country Market Cap P/E Price Change Volume

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")

Any solutions to the problem???

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!