Reputation: 61
I am stuck with this problem for like a day now and I have been searching endlessly regarding multi-threading so I figured I would just ask a question. So I wanted to create a program that would let me like/vote multiple links/image in a website with multiple accounts but it would require me to be logged in before voting. So far I have managed to login to the website with multiple accounts with my code using ThreadPoolExecutor, but I can't seem to get past the voting part(get request). So here are what I think are the issues:
Problem #1: I need to wait for all the accounts to login before doing the get requests.
Problem #2: The get requests are tied to every account. ex: If you logged in two facebook accounts, and tried to like an image, only one account would like the image. Should I make a different session per account?
from concurrent.futures import ThreadPoolExecutor
import requests
import threading
import time
from bs4 import BeautifulSoup
prefixUser = 'xxx'
passwordStr = 'xxx'
login_url = 'someLoginWebsite.com'
login_arr = []
for y in range(1, 3):
usernameStr = prefixUser + str(y)
login_data = {'username': usernameStr, 'password': passwordStr}
login_arr.append(login_data)
def fetch(session, login_data):
with session.post(login_url, data=login_data) as response:
for y in range(1, 9):
vote_url = 'urlForVoting.com/id=' + str(y)
a = session.get(vote_url)
with ThreadPoolExecutor(max_workers=10) as executor:
with requests.Session() as session:
executor.map(fetch, [session] * 200, login_arr)
executor.shutdown(wait=True)
I'm very new to python so hopefully I explained it clearly.
Upvotes: 0
Views: 85
Reputation: 413
In regards to Problem 1: You can perhaps create an array of "fake user" objects, spin up a thread for each object for them to sign in and wait for all the threads to terminate (ie. finish signing in). Afterwards you can delegate a thread for a different "vote" method for each object (which, if I'm understanding the problem correctly, is possible since all the accounts need to be logged in before any of them can vote).
Problem 2: You can create a Session object per Facebook account connection and assign the cookie given etc.
Upvotes: 1