Â
API - Python
Python Code Example
The following code using Python 3+ to output the PS Ratio in Valuation Ratio for WMT.
import urllib.request, json
response = urllib.request.urlopen('https://api.gurufocus.com/public/user/{api_token}/stock/WMT/keyratios')
content = response.read()
data = json.loads(content.decode('utf8'))
print(data['Valuation Ratio']['PS Ratio'])
The Python output of PS Ratio:
0.49
If you encountered "403 Forbidden error", please see this page. This is probably because of mod_security or some similar server security feature which blocks known spider/bot user agents (urllib uses something like python urllib/3.3.0, it's easily detected). Try setting a known browser user agent.
Continue to read: Code Examples - PHP