Great job
cosydney opened this issue ยท 11 comments
Hi Danny,
Love what you did with insta_scrape. I started using it and was pretty amazed of how easy it was to start scrapping profiles ..
I'm using this issue to drop a suggestion. Having number of likes and comments per post would be super cool.
I'm thinking of creating a web app that allows users to calculate their engagement rate vs other people so this would be super useful !
Hey Sydney -- I'll look into updating this with that new feature when I can. If you'd like to contribute, feel free to fork and pull!
I'll leave this issue open until the feature has been added / I've checked the possibility.
Thanks for reaching out! Glad you're enjoying the gem!
I'm looking into it and if I manage to make the feature on my side I'll make sure to contribute :).
Hi Danny,
to be frank I'm a little stuck, here is what I've been trying to do so far may be you can tell me how I should approach it.
Updated instagram_post.rb model:
class InstaScrape::InstagramPost
attr_accessor :link, :image, :likes
def initialize(link, image, likes)
@image = image
@link = link
@likes = likes
end
end
And updated insta_scrape.rb iterate_through_posts method
def self.iterate_through_posts
likes = 0;
all("article div div div a").each do |post|
link = post["href"]
image = post.find("img")["src"]
visit link
likes = page.first('section span span').text.to_i
info = InstaScrape::InstagramPost.new(link, image, likes)
@posts << info
end
#log
puts "POST COUNT: #{@posts.length}"
self.log_posts
#return result
return @posts
end
Do you know what I'm doing wrong? Thanks hips !
Hey,
I just managed to get likes by adding a function that I call from iterate_through_posts. This is the only way I managed so far.
def self.get_likes
@posts.each do |post|
visit post.link
post.likes = page.first('section span span').text.to_i
end
end
@cosydney I'll try and look into this when I get a moment. The solution you've posted above may be the only way. I'll have to explore.
@cosydney and @dannyvassallo I've been trying for the same. I tried the method you gave up
def self.iterate_through_posts likes = 0; all("article div div div a").each do |post| link = post["href"] image = post.find("img")["src"] visit link likes = page.first('section span span').text.to_i info = InstaScrape::InstagramPost.new(link, image, likes) @posts << info end
But am getting an error
NoMethodError: undefined method
text' for nil:NilClass
/var/lib/gems/2.2.0/gems/insta_scrape-1.1.1/lib/insta_scrape.rb:88:in block in iterate_through_posts' /var/lib/gems/2.2.0/gems/insta_scrape-1.1.1/lib/insta_scrape.rb:84:in
each'
/var/lib/gems/2.2.0/gems/insta_scrape-1.1.1/lib/insta_scrape.rb:84:in iterate_through_posts' /var/lib/gems/2.2.0/gems/insta_scrape-1.1.1/lib/insta_scrape.rb:132:in
scrape_posts'
/var/lib/gems/2.2.0/gems/insta_scrape-1.1.1/lib/insta_scrape.rb:10:in `hashtag'
Whats the difference between adding a separate function and including it in the def self.iterate_through_posts function. Please let me know how to solve this error.
Thanks
@cosydney checkout the new version of the gem and see if you can get likes in the block that visits the post to grab datetime.
Hey Danny will check thanks hips
@sruteesh use the new version of the gem!
@cosydney this is in the new release 1.1.3