Skip to content

Commit

Permalink
Hotfix on top of mariostoev#202
Browse files Browse the repository at this point in the history
To fix parsing the `company_details` due to an additional class `text-xl`
  • Loading branch information
taralika authored Nov 22, 2023
1 parent bc02ca9 commit d58aadc
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions finviz/main_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def get_page(ticker):
url=STOCK_URL, payload={"t": ticker}, parse=True
)


def get_stock(ticker):
"""
Returns a dictionary containing stock data.
Expand All @@ -32,13 +31,16 @@ def get_stock(ticker):
get_page(ticker)
page_parsed = STOCK_PAGE[ticker]

title = page_parsed.cssselect('table[class="fullview-title"]')[0]
keys = ["Ticker","Company", "Sector", "Industry", "Country"]
fields = [f.text_content() for f in title.cssselect('a[class="tab-link"]')]
data = dict(zip(keys, fields))

company_link = title.cssselect('a[class="tab-link"]')[0].attrib["href"]
title = page_parsed.cssselect('div[class="fv-container py-2.5"]')[0]
data = {}
data["Ticker"] = title.cssselect('h1[class="js-recent-quote-ticker quote-header_ticker-wrapper_ticker"]')[0].text_content().strip()
company_details = title.cssselect('h2[class="quote-header_ticker-wrapper_company text-xl"]')[0]
data["Company"] = company_details.text_content().strip()
company_link = company_details.cssselect('a[class="tab-link block truncate"]')[0].attrib["href"]
data["Website"] = company_link if company_link.startswith("http") else None
keys = ["Sector", "Industry", "Country", "Exchange"]
fields = [f.text_content() for f in title.cssselect('a[class="tab-link"]')]
data.update(dict(zip(keys, fields)))

all_rows = [
row.xpath("td//text()")
Expand Down

0 comments on commit d58aadc

Please sign in to comment.