Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Screener data and headers are empty #191

Open
NirAbramovich opened this issue Sep 30, 2023 · 9 comments · May be fixed by #193
Open

Screener data and headers are empty #191

NirAbramovich opened this issue Sep 30, 2023 · 9 comments · May be fixed by #193

Comments

@NirAbramovich
Copy link

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
Copy link

wfoor commented Oct 1, 2023

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

@sidward35
Copy link
Contributor

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

@sidward35 sidward35 linked a pull request Oct 2, 2023 that will close this issue
@josyjr25
Copy link

josyjr25 commented Oct 4, 2023

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
Copy link

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
Copy link

PBbanana commented Oct 6, 2023

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
Copy link

PBbanana commented Oct 9, 2023

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
Copy link

Any solutions to the problem???

@josyjr25
Copy link

josyjr25 commented Oct 19, 2023 via email

@jackomak
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants