本文摘自php中文网,作者PHP中文网,侵删。
Yahoo重新开放了天气API,不使用oauth只能每天获取2000次/ip
使用oauth获取天气的python代码如下,使用了requests_oauthlib进行认证
使用oauth获取天气的次数为每小时2w次,每天10w次。
使用前请注册一个Yahoo的APP获得key
# sudo pip install requests requests_oauthlib
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | import requests
from requests_oauthlib import OAuth1
consumerKey = <Your Consumer Key from Yahoo>
consumerSecret = <Your Consumer Secret from Yahoo>
baseurl = "https://query.yahooapis.com/v1/yql?"
yql_query = 'select * ' + 'from weather.forecast where woeid in'
yql_query + = ' (select woeid from geo.places(1) where text="%s") and u="c"' % "Beijing"
auth = OAuth1(consumerKey, consumerSecret)
result = requests.post(baseurl, data = { 'q' : yql_query, 'format' : 'json' }, auth = auth)
print result
print result.json()<br><br>
|
以上就是Yahoo Weather API with Oauth1的详细内容,更多文章请关注木庄网络博客!!
相关阅读 >>
实例详解Python3使用requests模块爬取页面内容
Python实现的求解最小公倍数算法示例
Python3中运算符的简单介绍
Python语言%表示什么
如何下载Python3.6
Python爬虫什么意思
Python file truncate() 方法是什么?能用在什么地方?
Python格式化输出%s和%d
树莓派怎么运行Python程序
Python基础知识点讲解
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » Yahoo Weather API with Oauth1