investpy icon indicating copy to clipboard operation
investpy copied to clipboard

investpy.get_stock_dividends could not convert string to float

Open zinovevvv opened this issue 2 years ago • 2 comments

Hello!

I get this error for some stocks:

In [2]: import investpy

In [3]: investpy.get_stock_dividends('USB', 'united states')

ValueError Traceback (most recent call last) in ----> 1 investpy.get_stock_dividends('USB', 'united states')

/usr/local/lib/python3.7/site-packages/investpy/stocks.py in get_stock_dividends(stock, country) 1167 element_.getnext() 1168 .text_content() -> 1169 .replace(",", "") 1170 ) 1171 if element_.get("data-value") in type_values.keys():

ValueError: could not convert string to float:

In [4]: i found this error with: SO US8425871071 GIS US3703341046 MRK US58933Y1055 PFE US7170811035 MO US02209S1033 USB US9029733048 VZ US92343V1044 IP US4601461035 BEN US3546131018 CAH US14149Y1082 BMY US1101221083 HPE US42824C1099 MET US59156R1086 ALV@DE DE0008404005 FRE@DE DE0005785604 MUV2@DE DE0008430026

zinovevvv avatar Jan 25 '22 19:01 zinovevvv

Hi, same problem here - I am looping through a list of stocks and getting dividents, but recently after adding a couple of new positions got that error as well:

Traceback (most recent call last):
  File "/Users/ash/opt/anaconda3/lib/python3.9/site-packages/investpy/stocks.py", line 908, in get_stock_dividends
    dividend_value = float(element_.getnext().text_content().replace(',', ''))

Code I am using to get dividents:

stock_info = investpy.stocks.get_stock_dividends(stock, country=country_data[countryiterator])

I managed to deal with this error by simply skipping stocks with such an error by using try/except clause like this:

except ValueError:
    print(' - ', stock, ' - DATA NOT FOUND')

I will try to dive into the source code and deal with this problem :)

Featuredutka avatar Feb 12 '22 21:02 Featuredutka

Added error list:

KO US PEP US O US

Mintsong42 avatar May 08 '22 04:05 Mintsong42