-3

I am making a bot that collects users from instagram. So far my program gives me this output on a txt file. How can I make python go through that and send a get requests using those specific id numbers?

LAST QUERY KEY BELOW
AQBLcJ2aIfiorfl1eraIX_g7PH-_ . 
H_poHpXHw1U2rhE4CV7H_nExtvEx05HKwD_2T6rPlcBehKB8FdG3QdKudTMUJl- 
qm6w9jjKJZrkzveEq9Q

ID NUMBERS: 1528791413      USERNAMES: ashleyzarrelli
ID NUMBERS: 5884571287      USERNAMES: kenyattacharmette
ID NUMBERS: 4110147842      USERNAMES: bihotza18
ID NUMBERS: 1917169763      USERNAMES: jenny_in_thecity
ID NUMBERS: 221371076      USERNAMES: grace_richardson97
ID NUMBERS: 6215684919      USERNAMES: bruce_the_little_big_dog
ID NUMBERS: 4762932342      USERNAMES: chickpea_chicks
ID NUMBERS: 6276498249      USERNAMES: bean3199
ID NUMBERS: 3117458992      USERNAMES: buziks.blog
ID NUMBERS: 417125559      USERNAMES: kristieannensley
ID NUMBERS: 416679367      USERNAMES: mavie_noelle
ID NUMBERS: 2165157745      USERNAMES: agent_phoo
Flimzy
  • 60,850
  • 13
  • 104
  • 147

2 Answers2

1

You can extract ID numbers through re.split(":? ", "string") to cover corner cases in your data sample, then use requests to build the GET requests.

The following stack overflow question can be of extra help. What is the quickest way to HTTP GET in Python?. More information about re and regular expressions can be found here

import re
import requests

data_file = open('data.txt','r') # update to reflect location of your .txt file
your_url = 'https://stackoverflow.com/posts' # update to reflect your target url

req_list =[]

for line in data_file:
    temp = re.split(":? ", line)
    if len(temp) > 2:
        if (temp[0],temp[1]) == ("ID","NUMBERS"):
            req_list.append(requests.get(your_url, params={'id': temp[2]}))        

print(req_list)
data_file.close()
helcode
  • 1,370
  • 1
  • 9
  • 28
0

Suppose that file.txt contains all the info that you posted. Try to use the requests python module to do the GET request. I believe that this is the code what you need:

import requests

a = open("file.txt")
for li in a.readlines():
    line = li.split(' ')
    if line[0] == 'ID':
        r = requests.get('https://api.example.com/user', params={'id': line[0]})
        print(r.status_code)