import pytchat import json import io strChat = "" video = input("video link: ") # print(video) chat = pytchat.create(video_id=video) f = io.open(video + ".html", 'a+', encoding='utf8') while chat.is_alive(): chatdata = chat.get() chatjson = chatdata.json() '''print(json.loads(chatjson),end='\n')''' jsonlist = json.loads(chatjson) for x in jsonlist: strChat = "" print(x['author']['name'], end=" - ") print(x['messageEx'], end=" - ") print(x['author']['channelUrl']) strChat = "
" + "\n" f.write(strChat) f.close()