-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInsta_Fetch.rb
More file actions
59 lines (45 loc) · 1.04 KB
/
Insta_Fetch.rb
File metadata and controls
59 lines (45 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
59
=begin
enumerate links
Loop check if more_available = "false" continue else exit loop
send_request
last id
image url
return links and last id
populate array with links
return array of links
Send request
send request to URL
parse json
return hashmap
=end
require 'json'
require 'open-uri'
BASE_uRL = "https://www.instagram.com"
def send_request(username, max_id)
url = "#{BASE_uRL}/#{ username }/media/?__a=1"
params = ""
params = "&max_id=#{max_id}" if max_id
# Return Hashmap of request
JSON.parse( open("#{url}#{params}", {ssl_verify_mode:0}).read )
end
def collect_links()
end
links = []
more_available = true
max_id = " "
while more_available == true do
data = send_request('sssniperwolf', max_id)
sleep(5)
items = data.fetch("items")
more_available = data.fetch("more_available")
max_id = items.last()["id"].split("_")[0]
items.each do |item|
links << item["images"]["standard_resolution"]["url"]
puts links
end
end
File.open("url.txt", 'w') do |file|
links.each do |link|
file.puts link
end
end