I had some Python 2 code as follows (pardon the indentation):
def getZacksRating(symbol):
c = httplib.HTTPSConnection("www.zacks.com")
c.request("GET", "/stock/quote/"+symbol)
response = c.getresponse()
data = response.read()
ratingPart = data.split('<p class="rank_view">')[1]
result = ratingPart.partition("<span")[0].strip()
return result
print getZacksRating("AAPL")
I changed it to (adding the b' ').
import http
def getZacksRating(symbol):
c = http.client.HTTPSConnection("www.zacks.com")
c.request("GET", "/stock/quote/"+symbol)
response = c.getresponse()
data = response.read()
ratingPart = data.split(b'<p class="rank_view">')[1]
result = ratingPart.partition(b"<span")[0].strip()
return result
print(getZacksRating('AAPL'))
The bad thing is it's getting printed as
print(getZacksRating('AAPL'))
b'Strong Buy'
I don't wish to see the b' '
in the output. Just want to see Strong Buy
being printed. Not very familiar with Python, hence any tip is appreciated.