在输出python中查找字符串?

时间:2017-06-27 19:30:54

标签: python youtube google-api

基本上,我试图通过在Google API的响应中查找字符串来检查youtube频道是否有效。如果字符串在那里,则频道是有效的,否则不是。

我的代码现在是

from urllib.request import urlopen
import json, time, codecs, re
    url = "https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=CHANNELID&type=video&eventType=live&key=KEY"
    response = urlopen(url)
    reader = codecs.getreader("utf-8")
    data = json.load(reader(response))
    print (data)

我怎样才能添加一些内容来检查""' liveBroadcastContent''生活"是在响应中并将值设置为true?感谢。

1 个答案:

答案 0 :(得分:0)

使用正则表达式搜索您提到的模式:

if 'livebroadcastcontent' in data:
    match=re.match(r'live', data)
    if match==true:
        print("its live")
相关问题