如何解决由于“隐藏”评论,无法抓取所有Instagram评论
我遇到了一些问题。 我写了一个脚本,应该抓取Instagram评论。一切都还不错,但是:这个脚本只刮取可见的注释(但是大多数注释都被该按钮隐藏了(“以英语显示更多”)。那么,如何修改我的脚本以刮除所有注释?
def get_comment_inst(post_link_list):
index = 0
comment_frame = pd.DataFrame(columns['text','user','time',"node_text",'node_name','node_time'])
for url_post in post_link_list:
params = '{'+'"shortcode":"{}"'.format(url_post[28:-1])+\
',"child_comment_count":3,"fetch_comment_count":40,"parent_comment_count":24,"has_threaded_comments":"true"' +'}'
url = 'https://www.instagram.com/graphql/query/?query_hash=eaffee8f3c9c089c9904a5915a898814&variables=' + params
wera = requests.get(url = url).json()
for i in wera['data']['shortcode_media']['edge_media_to_parent_comment']['edges']:
text = i['node']['text']
user = i['node']['owner']['username']
time_of_comment = time.ctime(int(i['node']['created_at']))
if (i['node']['edge_threaded_comments']['edges']):
for j in i['node']['edge_threaded_comments']['edges']:
node_text = j['node']['text']
node_name = j['node']['owner']['username']
node_time = time.ctime(j['node']['created_at'])
comment_frame.loc[index] = [text,user,time_of_comment,node_text,node_name,node_time]
index += 1
else:
node_text = ""
node_name = ""
node_time = ""
comment_frame.loc[index] = [text,node_time]
index += 1
return comment_frame
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。