Quantcast
Channel: Active questions tagged youtube-api - Stack Overflow
Viewing all articles
Browse latest Browse all 3638

How to resolve value error for a Youtube Comment and Reply Scraper function using Youtube API and Python

$
0
0

Am trying to create a function that uses Youtube API to fetch the comments and responses.

Please find my code below . This shows value error and doesn't work when am trying to store the data in DataFrame. I could understand that the issue is with the Reply Part but am not sure what went wrong. Any guidance or suggestions to tell me where I have gone wrong?

Update : I also noticed not all comments are getting extracted.

Thanks in Advance.

My Code :

def vid_comments():        Username = []        Comment = []        Comment_Likes = []        Comment_Date = []        Reply_Count = []        Reply = []        Replied_By = []        video_response=resource.commentThreads().list(part='snippet,replies',videoId=Video_ID).execute()        while video_response:            for item in video_response['items']:                item_info = item["snippet"]                topLevelComment = item_info["topLevelComment"]                comment_info = topLevelComment["snippet"]                Username.append(comment_info["authorDisplayName"])                Comment.append(comment_info["textDisplay"])                Comment_Likes.append(comment_info["likeCount"])                Comment_Date.append(comment_info['publishedAt'])                comment = item['snippet']['topLevelComment']['snippet']['textDisplay']                replycount = item['snippet']['totalReplyCount']                Reply_Count.append(replycount)                if replycount>0:                    for reply in item['replies']['comments']:                        reply_info = reply["snippet"]                        Reply.append(reply_info['textDisplay'])                        Replied_By.append(reply_info['authorDisplayName'])            if 'nextPageToken' in video_response:                p_token = video_response['nextPageToken']                video_response = resource.commentThreads().list(part = 'snippet,replies',videoId = Video_ID,pageToken = p_token).execute()            else:                break    vid_comments()    cmt_data = {'Comment': Comment,'Username':Username,'Comment Likes Count':Comment_Likes,'Comment Date':Comment_Date,'Reply Count':Reply_Count}    Comment_Section=pd.DataFrame(cmt_data)     reply_data = {'Reply':Reply,'Replied_By':Replied_By}    Reply_Section = pd.DataFrame(reply_data)  

I tried changing the indentations but thats not resolving the error . I tried creating a new list but again thats not helping.


Viewing all articles
Browse latest Browse all 3638

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>