Module: Grabber
- Included in:
- Instabot
- Defined in:
- lib/instabot/grabber.rb
Instance Method Summary collapse
- #get_media_informations(media_id) ⇒ Object
- #get_user_informations(user_id) ⇒ Object
- #search(tags = []) ⇒ Object
Instance Method Details
#get_media_informations(media_id) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/instabot/grabber.rb', line 24 def get_media_informations(media_id) puts '[+] '.cyan + "Trying to get media (#{media_id}) informations" log("Trying to get media (#{media_id}) informations", 'GRABBER') response = @agent.get("https://www.instagram.com/p/#{media_id}/?__a=1") data = parse_response(response.body) @informations = { id: data.deep_find('id'), full_name: data.deep_find('full_name'), owner: data.deep_find('owner')['username'], is_video: data.deep_find('is_video'), comments_disabled: data.deep_find('comments_disabled'), viewer_has_liked: data.deep_find('viewer_has_liked'), has_blocked_viewer: data.deep_find('has_blocked_viewer'), followed_by_viewer: data.deep_find('followed_by_viewer'), is_private: data.deep_find('is_private'), is_verified: data.deep_find('is_verified'), requested_by_viewer: data.deep_find('requested_by_viewer'), text: data.deep_find('text') } unless @infinite_tags == true = @informations[:text].encode('UTF-8', invalid: :replace, undef: :replace, replace: '?').split(/\W+/) id = 0 .each do |tag| if tag == '_' || tag == '' || tag.nil? .delete(tag) else id += 1 Config.. << tag end end puts '[+] '.cyan + '[' + id.to_s.yellow + '] New tags added' end end |
#get_user_informations(user_id) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/instabot/grabber.rb', line 2 def get_user_informations(user_id) puts '[+] '.cyan + "Trying to get user (#{user_id}) informations" log("Trying to get user (#{user_id}) informations", 'GRABBER') user_page = "https://www.instagram.com/web/friendships/#{user_id}/follow/" response = get_page(user_page) last_page = response.uri.to_s username = last_page.split('/')[3] response = @agent.get("https://instagram.com/#{username}/?__a=1") data = parse_response(response.body) @informations = { followers: data.deep_find('followed_by')['count'], following: data.deep_find('follows')['count'], is_private: data.deep_find('is_private'), is_verified: data.deep_find('is_verified'), username: data.deep_find('username'), posts: data.deep_find('media')['count'], full_name: data.deep_find('full_name'), id: data.deep_find('id') } end |
#search(tags = []) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/instabot/grabber.rb', line 60 def search( = []) .each do |tag| puts '[+] '.cyan + "Searching in hashtag [##{tag}]" log("Searching in hashtags [##{tag}]", 'GRABBER') url = "https://www.instagram.com/explore/tags/#{tag}/?__a=1" response = @agent.get(url) data = parse_response(response.body) owners = data.deep_find_all('owner') media_codes = data.deep_find_all('code') owners.map { |id| users << id['id'] } media_codes.map { |code| medias << code } Config...delete(tag) end puts '[+] '.cyan + 'Total grabbed users [' + users.size.to_s.yellow + ']' puts '[+] '.cyan + 'Total grabbed medias [' + medias.size.to_s.yellow + ']' log("Total grabbed users(#{users.size}) & Total grabbed medias(#{medias.size})", 'GRABBER') end |