Created
July 4, 2021 13:35
-
-
Save xiangzhuyuan/e5ef3eb769c505aac74d8d170bd01202 to your computer and use it in GitHub Desktop.
get instagram following list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/http' | |
require 'uri' | |
require 'json' | |
require 'byebug' | |
followers = [] | |
1000000.times do |t| | |
target = "https://i.instagram.com/api/v1/friendships/35182405/following/?count=#{12 * t}12&max_id=#{0 + 12 * t}" | |
uri = URI.parse(target) | |
request = Net::HTTP::Get.new(uri) | |
request["Authority"] = "i.instagram.com" | |
request["Pragma"] = "akamai-x-get-client-ip, akamai-x-cache-on, akamai-x-cache-remote-on, akamai-x-check-cacheable, akamai-x-get-cache-key, akamai-x-get-extracted-values, akamai-x-get-nonces, akamai-x-get-ssl-client-session-id, akamai-x-get-true-cache-key, akamai-x-serial-no, akamai-x-feo-trace, akamai-x-get-request-id" | |
request["Cache-Control"] = "no-cache" | |
request["Sec-Ch-Ua"] = "\" Not;A Brand\";v=\"99\", \"Google Chrome\";v=\"91\", \"Chromium\";v=\"91\"" | |
request["Dnt"] = "1" | |
request["X-Ig-Www-Claim"] = "hmac.AR3XdOZS-MFiB-R9gRRSLGdhBxM_ecNE9bEM0vURLINBfbFX" | |
request["Sec-Ch-Ua-Mobile"] = "?0" | |
request["User-Agent"] = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36" | |
request["Accept"] = "*/*" | |
request["X-Asbd-Id"] = "437806" | |
request["X-Ig-App-Id"] = "936619743392459" | |
request["Origin"] = "https://www.instagram.com" | |
request["Sec-Fetch-Site"] = "same-site" | |
request["Sec-Fetch-Mode"] = "cors" | |
request["Sec-Fetch-Dest"] = "empty" | |
request["Referer"] = "https://www.instagram.com/" | |
request["Accept-Language"] = "zh-CN,zh;q=0.9,ja;q=0.8,en;q=0.7,zh-TW;q=0.6" | |
request["Cookie"] = "ig_did=7BD7D46B-A7C4-4AC0-B694-96CB04EE0077; ig_nrcb=1; mid=YEY2EwAEAAFFQYHJ7oO-GOvKfOmh; fbm_124024574287414=base_domain=.instagram.com; csrftoken=sUc4ijuMHSuIYtb8IjDLqv4nmPI0z9Ub; ds_user_id=35182405; sessionid=35182405%3ArUK9GGeVKNtiwX%3A29; shbid=13821; shbts=1625375104.8416965; rur=FRC; fbsr_124024574287414=Oohhw1C-txkFWNm4FGY4aGL1zixWdo_aYUKbh6-CG_w.eyJ1c2VyX2lkIjoiMTgyNjk2NjQ3NCIsImNvZGUiOiJBUUQ0cDIzMzYwZ3J3Z09PRElKbkxSSmdFMmtOb2lOUVQ3MDRxMHNFaGVfazR2NUxfVXZYQzFJRF95MVdkWmEwRXk2XzMzczhPdkpfYUFLZWp1MF80U25MbmtNSHhyTWVRcG1Nc1AxdWx3Rk9VTFczM3Q1WmxRRTdnMzZZQ3RkdHU2SEwtZ0pWTndsY3VhdnRiN1duQm84M1M0blVGZjhpOHQ5cE9ZVHp0NjREWDloVVh6WFZtSkVUMGtpSXV6NFNqQ2JGX3lDZDFkbTBSSDdJVlJva3YzVVpNVXVERmVGTHVtZTg1NzllMTNOSW1wYXZmMGYxNWJwWFNqOEdnYlBuME1DenpDS1hPQmdJaVB5NkZ3eVJIazU1MXR6OXBnejd0TGJkeU10Z0UtRzBVakNhSmdqZzBvNVpLckxwYXg1aEdEYyIsIm9hdXRoX3Rva2VuIjoiRUFBQnd6TGl4bmpZQkFPcWVhNHRYMVVaQm9XR2NsNnBkSkdnYk96a0FhNlpDVGhJeFZTWExXQTNPakxLT0U2Qk1QdlJzdXhLVFdyWWdsT3V0R3Y2cVRhNTJTcGhSNGlsemlaQVIzZWdVVTdNUTVpSzRqalhuSE5lUXhkV055NUtQdDA2UXNlM0ZEdW51MTY2TE1STFl0Q09zM09QNjVXNExQTk90d1pCU1FLR0cwMkRBSjF5ZiIsImFsZ29yaXRobSI6IkhNQUMtU0hBMjU2IiwiaXNzdWVkX2F0IjoxNjI1NDAxNDc2fQ" | |
req_options = { | |
use_ssl: uri.scheme == "https", | |
} | |
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http| | |
http.request(request) | |
end | |
puts response.code | |
users = JSON.parse(response.body)['users'] | |
break if users.empty? | |
followers << JSON.parse(response.body)['users'].map { |u| "#{u['username']} ... #{u['full_name']}" } | |
end | |
`touch users.txt && truncate --size 0 users.txt` | |
puts followers | |
File.open('users.txt', 'wb') do |f| | |
f.write followers.join("\n") | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment