Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
111 views
in Technique[技术] by (71.8m points)

javascript - I can't get Instagram comments because of the pagination

My friend and I are trying to use Instagram Scraping. When we try to get Instagram post's comments we didn't manage to get results. Because of we couldn't get the request URL from Network tab/XHR and Fetch. To more clear here our codes;

$.ajax({
url:"https://www.instagram.com/p/CKbQLm3qXhN/?__a=1",
type:'get',
success:function(response){
var list = [];
var list2 = [];
var lengthh = response.graphql.shortcode_media.edge_media_to_parent_comment.edges.length;
var comments = response.graphql.shortcode_media.edge_media_to_parent_comment.count;
console.log(comments);
console.log(lengthh);
console.log(response.url);
for (var i=0;i<lengthh;i++)
{
  list.push(response.graphql.shortcode_media.edge_media_to_parent_comment.edges[i].node.text);
  list2.push(response.graphql.shortcode_media.edge_media_to_parent_comment.edges[i].node.owner.username);
}
console.log(list);
console.log(list2);
}});

We can get just a little bit comments with that codes. But we want all of the comments.

When we use the code that I shared below this code automatically runs the Show more comments button every time it runs. So Instagram shows us more comments, actually 12 more commments. Each new 12 comments are uploaded to a separate page.

document.querySelector("#react-root > section > main > div > div.ltEKP > article > div.eo2As > div.EtaWk > ul > li > div > button > span").click();

The comments are uploaded in pages to another URL. We also need to reach those URLs and get the comments. How can we get the URL which I shared below.

Click to see image

question from:https://stackoverflow.com/questions/65894379/i-cant-get-instagram-comments-because-of-the-pagination

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...