Skip to content Skip to sidebar Skip to footer

Using Python 3 To Retrieve Stock Information From Yahoo Finance Site

I have been trying to port a script which will request fundamental data from Yahoo Finance site, but I would like to look for specific items instead of the entire reports, like pri

Solution 1:

It looks like urllib.request.urlopen and .read() is returning data with type bytes.

From the python docs:

Note that urlopen returns a bytes object. This is because there is no way for urlopen to automatically determine the encoding of the byte stream it receives from the http server. In general, a program will decode the returned bytes object to string once it determines or guesses the appropriate encoding.

The split method is failing here. Try appending .decode() after .read(). The issue is that you are trying to split the sourceCode variable which is of type bytes by a string. Decoding sourceCode will convert it from bytes to string. Alternatively, you could .encode() both of your delimiters.

bytes.decode


Post a Comment for "Using Python 3 To Retrieve Stock Information From Yahoo Finance Site"