使用urllib库使用python从thingspeak读取数据

时间:2018-04-11 10:36:22

标签: json python-2.7 iot

我想从thingspeak网站上阅读当前数据 我使用urllib库来使用通道的读取URL来获取数据

我使用了python代码

import urllib
from bs4 import BeautifulSoup
data=urllib.urlopen("https://api.thingspeak.com/channels/my_channel_no/feeds.json? 
results=2")
print data.read()
select=repr(data.read())
print select
sel=select[20:]
print sel


https://api.thingspeak.com/channels/my_channel_no/feeds.json?results=2

我从查询中得到了这个结果

'{"channel{"id":my_channel_no,"name":"voltage","latitude":"0.0","longitude":"0.0 ","field1":"Field Label 1","field2":"Field Label 2","created_at":"2018-04-05T16:33:14Z","updated_at":"2018-04-09T15:39:43Z","last_entry_id":108},"feeds":[{"created_at":"2018-04-09T15:38:42Z","entry_id":107,"field1":"20.00","field2":"40.00"},{"created_at":"2018-04-09T15:39:44Z","entry_id":108,"field1":"20.00","field2":"40.00"}]}'

但是当这一行被执行时

select=repr(data.read())

结果是

"''"

并且

sel=select[20:]

输出

''

这用于减少查询的长度  任何人都可以给我一些方向感,这个目标选择的解决方案就是目标。

0 个答案:

没有答案