It looks like Google Finance has changed its URLs / endpoints, and the googlefinance package googlefinance not been updated to reflect this change.
Since most of these changes are pretty opaque to end users (and the library you use has not been updated after 2 years), you might be better off with a raw Google Finance answer.
Google Finance Endpoint
You can get information about a specific ticker symbol at the following URL:
https:
Answer
Google Finance returns JSON results in this format
\n// [\n{\n"symbol" : "AAPL",\n"exchange" : "NASDAQ",\n"id": "22144",\n"t" : "AAPL",\n"e" : "NASDAQ",\n"name" : "Apple Inc."\n, "f_reuters_url" : "http:\\x2F\\x2Fstocks.us.reuters.com\\x2Fstocks\\x2Fratios.asp?rpc=66\\x26symbol=AAPL.O",\n"f_recent_quarter_date" : "Q3 (Jul \\x2717)",\n"f_annual_date" : "2016",\n"f_ttm_date" : "2015",\n"financials" : ... a lot more stuff ... [\n]\n}]\n'
It cannot be loaded with the Python JSON as-is parser because it has a leading // and wraps everything inside [] . It also has Unicode-escaped characters in various lines that need to be decoded.
Full code and parsing
I am going to use the requests module for this, but if you need an example with a built-in urllib module, I can also show this.
import json import requests rsp = requests.get('https://finance.google.com/finance?q=AAPL&output=json') if rsp.status_code in (200,): # This magic here is to cut out various leading characters from the JSON # response, as well as trailing stuff (a terminating ']\n' sequence), and then # we decode the escape sequences in the response # This then allows you to load the resulting string # with the JSON module. fin_data = json.loads(rsp.content[6:-2].decode('unicode_escape')) # print out some quote data print('Opening Price: {}'.format(fin_data['op'])) print('Price/Earnings Ratio: {}'.format(fin_data['pe'])) print('52-week high: {}'.format(fin_data['hi52'])) print('52-week low: {}'.format(fin_data['lo52']))
This will lead to the conclusion:
Opening Price: 162.71 Price/Earnings Ratio: 18.43 52-week high: 164.94 52-week low: 102.53
There is much more data that is included in the full JSON code than what I output, so it's up to you how you want to use it.
Alternatives
Alternatively, you can use the yahoo-finance module, which is probably less likely to have problems like Yahoo still provides real API funding.