def generate_register_data(): # 生成注册数据返回 try: registerData = {} registerData['domain_code'] = "www" registerData['captcha_response'] = None firstname = generate_random_string(8, 12) lastname = generate_random_string(8, 12) password = generate_random_string(10, 14) email = firstname + '@hotmail.com' account = { 'email': email, 'password': password, 'firstname': firstname, 'lastname': lastname, 'disclaimer_input': True, 'general_opt_in': False, 'source': None } registerData['account'] = account except Exception as e: g_var.ERR_CODE = 5000 g_var.ERR_MSG = "注册数据生成中出现异常..." g_var.logger.info("注册数据生成中出现异常...") g_var.logger.info(e) return -2 return registerData
def __register_one(self, Session, present_website: str): # user,pass, try: headers = {} headers['Connection'] = 'close' headers['user_agent'] = project_util.get_user_agent() res = Session.get("https://www.reddit.com/register/?actionSource=header_signup",proxies=Session.proxies, headers=headers, timeout=g_var.TIMEOUT) re_res = re.search('<input type="hidden" name="csrf_token" value="(.*?)">', res.text) if re_res.group(): csrf_token = re_res.group(1) else: g_var.ERR_CODE = "2001" g_var.ERR_MSG = g_var.ERR_MSG + "|_|没有获取到token" g_var.logger.error("没有获取到token") return -1 google_code = project_util.google_captcha(requests.session(), "6LeTnxkTAAAAAN9QEuDZRpn90WwKk_R1TRW_g-JC", "https://www.reddit.com") if len(google_code) < 5: g_var.ERR_CODE = "2010" g_var.ERR_MSG = g_var.ERR_MSG + "|_|" g_var.logger.error("没有获取到谷歌验证码") user = project_util.generate_random_string(6, 12) pwd = project_util.generate_random_string(10, 16) email = user + "@hotmail.com" data = { "csrf_token": csrf_token, "g-recaptcha-response": google_code, "dest": "https://www.reddit.com", "password": pwd, "username": user, "email": email, } # headers["content-type"]="application/x-www-form-urlencoded" res = Session.post("https://www.reddit.com/register", headers=headers,proxies=Session.proxies, data=data, timeout=g_var.TIMEOUT) # if res.json():#成功结果:{"dest": "https://www.reddit.com"} if self.__dictExistValue(res.json(), "dest"): self.captcha_err_count = 0 sql = "INSERT INTO reddit_com(username, password, mail, status) VALUES('" + user + \ "', '" + pwd + "', '" + email + "', '" + str(0) + "');" print("正在进入sql:", sql) last_row_id = MysqlHandler().insert(sql) if last_row_id != -1: userId = last_row_id return {'user_id': userId, 'name': user, 'password': pwd, 'mail': email} else: g_var.logger.error("数据库插入失败") return -1 else: g_var.logger.info("验证码错误或邮箱名重复!result:", res.text) self.captcha_err_count = self.captcha_err_count + 1 return -1 except Exception as e: g_var.ERR_CODE = "2100" g_var.ERR_MSG = g_var.ERR_MSG + "|_|"+"ip出现问题 请求失败" g_var.logger.info("未知错误:", e) return -1
def generate_register_data(authenticity_token): # 生成注册数据返回 name = generate_random_string(8, 12) email = name + '@hotmail.com' password = generate_random_string(10, 14) registerData = { 'authenticity_token': authenticity_token, 'user[login]': name, 'user[email]': email, 'user[password]': password, 'commit': 'Create Account', } return registerData
def register() -> (str, str, str): user = project_util.generate_random_string(12, 16) pwd = project_util.generate_random_string(10, 12) email = user + "@qq.com" dicproxy = ip_proxy() s = requests.session() s.proxies = dicproxy s.headers = headers proxies = ip_proxy() res = requestsW.get( "https://www.reddit.com/register/?actionSource=header_signup", proxies=proxies, headers=headers, timeout=5) cookies = res.cookies.get_dict() print(cookies) print("已经响应", res) re_res = re.search('<input type="hidden" name="csrf_token" value="(.*?)">', res.text) csrf_token = re_res.group(1) print("正在打码中") # g_recaptcha_response = captcha() g_recaptcha_response = "03AGdBq24tyZjh-Ini2ud5ISBy1Eb-UYEpSKYdgxsNNLLvMRQT4VXCVW4Z1EuXrtX4GwlERbjJkS1x9cJtcPbKmGYwzvqRfajGUvFyq9CEfRSzohkPv54Lnk1BlU3OHE8suDOSrKwc90uj7TPeTL12VUhdyCk-H73quiajTYNuwd3pJm1xdWbbo4JthN8N0hvMIrsdM7_XYAclp_BN9QTWkwmhjDTpR8-CM2zWJ48JKug-9KZzaVM-Bmxzb7LVr4NcG5XozTrhsIdbS89eLSo8aoS7V-frd8Hb6xFpBpvjtsCQMnE25FoR7FqPmL2ER0bNV7QgowFX6Z8OFZ95fDDTub5S9qCQUr7Zactpz57_W38T6opn4u4swVH_EcEGUpkT1IhUgy5GVVsBgvidVR3F0j7F5tfLQ2_GKg" print("打印验证码:", g_recaptcha_response) data = { "csrf_token": csrf_token, "g-recaptcha-response": g_recaptcha_response, "dest": "https://www.reddit.com", "password": pwd, "username": user, "email": email, } # res.headers["content-type"]="application/x-www-form-urlencoded" res = requestsW.post("https://www.reddit.com/register", headers=headers, proxies=proxies, cookies=cookies, data=data, timeout=5) print(res.cookies) print("注册结果:", res.text)
def generate_register_data(email_info, captcha_value): # 生成注册数据返回 try: name = generate_random_string(10, 12) password = generate_random_string(10, 14) registerData = { "firstName": name, "lastName": "", "email": email_info[0], "password": password, "approvedEmailMarketing": False, "captchaResponse": captcha_value, } except Exception as e: g_var.ERR_CODE = 5000 g_var.ERR_MSG = "注册数据生成中出现异常..." g_var.logger.info("注册数据生成中出现异常...") g_var.logger.info(e) return -1 return registerData
def generate_register_data(present_website, email_info): # 生成注册数据返回,并存入数据库 try: username = generate_random_string(8, 12) password = generate_random_string(10, 14) registerData = { 'signup-from': 'new_landing_undefined', 'form-type': '', 'username': username, 'email': email_info[0], 'password': password, 'month': '05', 'day': '21', 'year': '1999', } except: g_var.logger.info("注册数据生成中出现异常...") return -1 return registerData
def generate_register_data(email_info, captcha_value, tok): # 生成注册数据返回 try: password = generate_random_string(10, 14) data_user = { 'email': email_info[0], 'password1': password, 'password2': password, 'g-recaptcha-response': captcha_value, 'action': 'add_step0', 'Submit.x': '60', 'Submit.y': '25', 'tok': tok, } except Exception as e: g_var.ERR_CODE = 5000 g_var.ERR_MSG = "注册数据生成中出现异常..." g_var.logger.info("注册数据生成中出现异常...") g_var.logger.info(e) return -1 return data_user
def __register_one(self, present_website, email_and_passwd): """ 注册一个账户,需要实现注册、激活、并将注册数据存入数据库的功能 Args: Session:Session对象 present_website:当前网站名,用于数据库表名 email_and_passwd:邮箱账户和密码,email_and_passwd[0]是邮箱,[1]是密码 Returns: 注册成功返回注册数据字典对象registerData,需要包含id, username, password, email, cookie(在访问激活链接时能取到,\ 取不到返回空) user_id这样获取:(示例) # 将注册的账户写入数据库(sql自己写,这边只是个示例) sql = "INSERT INTO "+present_website+"(username, password, mail, status, cookie) VALUES('" + \ username + "', '" + password + "', '" + email + "', '" + str(0) + cookie + "');" last_row_id = MysqlHandler().insert(sql) if last_row_id != -1: registerData["user_id"] = last_row_id return registerData else: g_var.logger.error("数据库插入用户注册数据失败") return 0 注册失败返回状态码 0:某些报错需要跳出while循环,更换邮箱 -1:连续代理错误或页面发生改变等取不到关键数据等,需要停止程序 -2:注册失败,可能是打码出错等原因,邮箱可以继续使用(邮箱资源成本较高,因此要确保注册成功后再更换邮箱),不跳出循环 """ g_var.logger.info('register......') url = 'http://www.liveinternet.ru/journal_register.php' headers = generate_headers(0) if headers == -1: g_var.logger.info("获取headers失败...") return -1 tok = get_tok(url, headers) if tok == -1: return -1 elif tok == -2: return -2 googlekey = '6Lcl3BYUAAAAAG1gTAOhNtJIeTrPn68melrC1gbV' captcha_value = google_captcha("", googlekey, url) if captcha_value == -1: return -2 registerData = generate_register_data(email_and_passwd, captcha_value, tok) headers['Origin'] = 'http://www.liveinternet.ru' headers['Referer'] = 'http://www.liveinternet.ru/journal_register.php' headers['Content-Type'] = 'application/x-www-form-urlencoded' g_var.logger.info("提交注册中...") html = requestsW.post(url, proxies=ip_proxy("en"), data=registerData, headers=headers, timeout=g_var.TIMEOUT) if html == -1: return html # 第一步注册成功与否的验证 result = re.findall(email_and_passwd[0], html.text) if len(result) != 2: g_var.logger.info("第一步注册失败...") g_var.logger.info(html.status_code) return -2 # 邮箱验证 time.sleep(2) verify_url = get_verify_url(email_and_passwd) if verify_url == 0: g_var.logger.info("未读取到邮箱验证的url...") return 0 # 邮箱验证的tok获取 email_tok = get_tok_email(verify_url) if email_tok == -1: return 0 elif email_tok == -2: return 0 id = re.findall('id=(.*?)&', verify_url)[0] h = re.findall('h=(.*)', verify_url)[0] headers['Referer'] = verify_url captcha_value = google_captcha("", googlekey, verify_url) if captcha_value == -1: return 0 username = generate_random_string( 10, 12, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") day = str(random.randint(1, 28)) month = str(random.randint(1, 12)) year = str(random.randint(1980, 2010)) sex = ['M', 'W'] multipart_encoder = MultipartEncoder( fields={ 'username': username, 'comm': '0', 'sexchar': random.choice(sex), 'day': day, 'month': month, 'year': year, 'city': '1870', 'icq': '', 'emails': '', 'addinfo': username, 'avatarfile': ('', '', 'application/octet-stream'), 'g-recaptcha-response': captcha_value, 'dailynews': '1', 'Submit.x': '80', 'Submit.y': '20', 'familyname': '', 'firstname': '', 'password': registerData['password1'], 'email': email_and_passwd[0], 'passwordconfirm': registerData['password1'], 'imagehash': '', 'regkey': '', 'invite_id': '0', 'regkeynb': '', 'url_redirect': '', 'url2': '', 'action': 'add_step1', 'h': h, 'id': id, 'tok': email_tok, }, boundary='----WebKitFormBoundary' + generate_random_string( 16, 16, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'), ) headers['Content-Type'] = multipart_encoder.content_type g_var.logger.info("注册第二步,邮箱验证提交信息中...") url_email_prove = 'http://www.liveinternet.ru/journal_register.php' html = requestsW.post(url_email_prove, proxies=ip_proxy("en"), data=multipart_encoder, headers=headers, allow_redirects=False, timeout=g_var.TIMEOUT) if html == -1: return html if not html.headers.get('Set-Cookie', None): g_var.logger.info('第二步邮箱验证信息提交失败...') return 0 # 将注册的账户写入数据库 try: set_cookie = html.headers['Set-Cookie'] user_Id = re.findall('bbuserid=(.*?);', set_cookie) user_password = re.findall('bbpassword=(.*?);', set_cookie) cookie = user_Id[0] + '|_|' + user_password[0] sql = "INSERT INTO " + present_website + "(username, password, mail, cookie) VALUES('" + \ username + "', '" + registerData['password1'] + "', '" + email_and_passwd[0] + "', '" + cookie + "');" last_row_id = MysqlHandler().insert(sql) g_var.logger.info(last_row_id) if last_row_id != -1: g_var.logger.info('注册成功!' + username) userData = { 'id': last_row_id, 'username': username, 'password': registerData['password1'], 'cookie': cookie, } return userData else: g_var.ERR_CODE = 2004 g_var.ERR_MSG = "数据库插入用户注册数据失败..." g_var.logger.error("数据库插入用户注册数据失败...") return 0 except Exception as e: g_var.logger.info(e) g_var.ERR_CODE = 2004 g_var.ERR_MSG = "数据库插入用户注册数据异常..." g_var.logger.error("数据库插入用户注册数据异常...") return 0
def __register_one(self, Session, present_website: str, email_and_passwd): """ 注册一个账户,需要实现注册、激活、并将注册数据存入数据库的功能 Args: Session:Session对象 present_website:当前网站名,用于数据库表名 email_and_passwd:邮箱账户和密码,email_and_passwd[0]是邮箱,[1]是密码 Returns: 注册成功返回注册数据字典对象registerData,需要包含id, username, password, email, cookie(在访问激活链接时能取到,\ 取不到返回空) user_id这样获取:(示例) # 将注册的账户写入数据库(sql自己写,这边只是个示例) sql = "INSERT INTO "+present_website+"(username, password, mail, status, cookie) VALUES('" + \ username + "', '" + password + "', '" + email + "', '" + str(0) + cookie + "');" last_row_id = MysqlHandler().insert(sql) if last_row_id != -1: registerData["user_id"] = last_row_id return registerData else: g_var.logger.error("数据库插入用户注册数据失败") return 0 注册失败返回状态码 0:某些报错需要跳出while循环,更换邮箱 -1:连续代理错误或页面发生改变等取不到关键数据等,需要停止程序 -2:注册失败,可能是打码出错等原因,邮箱可以继续使用(邮箱资源成本较高,因此要确保注册成功后再更换邮箱),不跳出循环 """ username = generate_random_string(15, 20) password = generate_random_string(10, 15) g_var.logger.info("username:"******"password:"******"https://pastebin.com/etc/captcha/random.php" captcha_code = identify_captcha_1(Session, captcha_url, present_website) if captcha_code == -1: g_var.logger.info("代理连续错误") return -1 elif captcha_code == -2: g_var.logger.info("识别验证码失败") return -2 g_var.logger.info("captcha_code:" + captcha_code) registerData = { 'user_notifications': '1', 'submit_hidden': 'submit_hidden', 'user_name': username, 'user_email': email_and_passwd[0], 'user_password': password, 'user_terms': 'on', 'captcha_solution': captcha_code, 'submit': 'Create My Account', } headers = { 'content-type': 'application/x-www-form-urlencoded', 'origin': 'https://pastebin.com', 'referer': 'https://pastebin.com/signup', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36', } url = "https://pastebin.com/signup.php" result = Session.post(url, headers=headers, data=registerData, timeout=g_var.TIMEOUT) if result == -1: g_var.logger.error("提交注册信息超时") return -1 success_signal = "Please click on the activation link to activate your account." if success_signal in result.text: g_var.logger.info("注册成功!" + result.text) else: email_used_signal = "The email address you picked is already in use" if email_used_signal in result.text: g_var.logger.info("邮箱已经被注册!" + result.text) return 0 # 跳出循环更换邮箱 re_text = '(https://pastebin.com/activate_account.php\?.*?)"' email_verify_obj = EmailVerify(email_and_passwd[0], email_and_passwd[1], re_text) verify_url = account_activation(Session, email_verify_obj) if verify_url == -1: g_var.logger.info("2分钟内未收到激活邮件,激活失败!") resend_url = "https://pastebin.com/resend.php" headers = { ':authority': 'pastebin.com', ':method': 'POST', ':path': '/resend.php', ':scheme': 'https', '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, br', 'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8', 'cache-control': 'max-age=0', 'content-type': 'application/x-www-form-urlencoded', 'cookie': '__cfduid=d4e164af370e44d4de219e208cd6779061589887894; PHPSESSID=8ehi7ipdvopsmtqq9oaf1uk000; _ga=GA1.2.65423653.1589887895; _gid=GA1.2.805292117.1589887895; refit=L3Byb2ZpbGU%3D; _gat_UA-58643-34=1', 'origin': 'https://pastebin.com', 'referer': 'https://pastebin.com/resend.php?e=3', 'sec-fetch-dest': 'document', 'sec-fetch-mode': 'navigate', 'sec-fetch-site': 'same-origin', 'sec-fetch-user': '******', 'upgrade-insecure-requests': '1', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36', } resendData = {} result = Session.post(resend_url, headers=headers, data=resendData, timeout=g_var.TIMEOUT) if result == -1: g_var.logger.error("提交重新激活超时") return -1 verify_url = account_activation(Session, email_verify_obj) if verify_url == -1: g_var.logger.error("又没激活成功") return 0 g_var.logger.info("verify_url" + verify_url) headers = { 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36', } result = Session.get(url=verify_url, headers=headers, timeout=g_var.TIMEOUT) if result == -1: g_var.logger.error("访问激活链接超时") return -1 # 获取cookie cookie = str(Session.cookies.get_dict()) sql = "INSERT INTO " + present_website + "(username, password, mail, status, cookie) VALUES('" + username + \ "', '" + password + "', '" + email_and_passwd[0] + "', '" + str(0) + "', \"" + cookie + "\");" last_row_id = MysqlHandler().insert(sql) if last_row_id != -1: registerData = dict() registerData["id"] = last_row_id registerData['username'] = username registerData['password'] = password registerData['email'] = email_and_passwd[0] registerData['cookie'] = cookie return registerData else: g_var.logger.error("数据库插入用户注册数据失败") return 0
def __send_profile(self, userData): """ 发个人简介 Args: Session:Session对象 loginData:用户信息,包括user_id,username,password,email,cookie Returns: 成功返回:0 失败返回状态值: 1:数据库存储失败 -1:连续代理错误或页面发生改变等取不到关键数据等,需要停止程序 -2:本次出错,继续循环 """ g_var.logger.info('send profile......') headers = generate_headers(1) if headers == -1: return -1 g_var.logger.info('authenticity_token, session_id...') authenticity_token, session_id = get_authenticity_token(userData) if authenticity_token == -1 or session_id == -1: return -1 elif authenticity_token == -2 or session_id == -2: return 1 headers['Referer'] = 'https://www.sbnation.com/users/' + userData[ 'username'] + '/edit_profile' headers['Cookie'] = '_session_id=' + session_id titleLink = get_new_title_and_link() if titleLink == -1: return -1 multipart_encoder = MultipartEncoder( fields={ 'utf8': '✓', '_method': 'patch', 'authenticity_token': authenticity_token, 'profile_image[filename]': ('', '', 'application/octet-stream'), 'profile_image[filename_cache]': '', 'network_membership[bio]': '', 'network_membership[signature]': '', 'network_membership[public_email]': '', 'network_membership[website_name]': titleLink[0], 'network_membership[website_url]': titleLink[1], 'network_membership[facebook_page_url]': '', 'network_membership[facebook_page_url]': '', 'network_membership[network_membership_items_attributes][0][key]': 'MLB', 'network_membership[network_membership_items_attributes][0][value]': '', 'network_membership[network_membership_items_attributes][1][key]': 'NFL', 'network_membership[network_membership_items_attributes][1][value]': '', 'network_membership[network_membership_items_attributes][2][key]': 'NBA', 'network_membership[network_membership_items_attributes][2][value]': '', 'network_membership[network_membership_items_attributes][3][key]': 'NHL', 'network_membership[network_membership_items_attributes][3][value]': '', 'network_membership[network_membership_items_attributes][4][key]': 'NCAAF', 'network_membership[network_membership_items_attributes][4][value]': '', 'network_membership[network_membership_items_attributes][5][key]': 'NCAAB', 'network_membership[network_membership_items_attributes][5][value]': '', 'network_membership[network_membership_items_attributes][6][key]': 'MMA', 'network_membership[network_membership_items_attributes][6][value]': '', 'network_membership[network_membership_items_attributes][7][key]': 'Golf', 'network_membership[network_membership_items_attributes][7][value]': '', 'network_membership[network_membership_items_attributes][8][key]': 'NASCAR', 'network_membership[network_membership_items_attributes][8][value]': '', 'network_membership[network_membership_items_attributes][9][key]': 'Boxing', 'network_membership[network_membership_items_attributes][9][value]': '', 'network_membership[network_membership_items_attributes][10][key]': 'Soccer', 'network_membership[network_membership_items_attributes][10][value]': '', 'network_membership[network_membership_items_attributes][11][key]': 'MLS', 'network_membership[network_membership_items_attributes][11][value]': '', 'network_membership[network_membership_items_attributes][12][key]': 'EPL', 'network_membership[network_membership_items_attributes][12][value]': '', 'network_membership[network_membership_items_attributes][13][key]': 'Football League Championship', 'network_membership[network_membership_items_attributes][13][value]': '', 'network_membership[network_membership_items_attributes][14][key]': 'FIFA', 'network_membership[network_membership_items_attributes][14][value]': '', 'network_membership[network_membership_items_attributes][15][key]': 'Bundesliga', 'network_membership[network_membership_items_attributes][15][value]': '', 'network_membership[network_membership_items_attributes][16][key]': 'Serie A', 'network_membership[network_membership_items_attributes][16][value]': '', 'network_membership[network_membership_items_attributes][17][key]': 'La Liga', 'network_membership[network_membership_items_attributes][17][value]': '', 'network_membership[network_membership_items_attributes][18][key]': 'Cycling', 'network_membership[network_membership_items_attributes][18][value]': '', 'network_membership[network_membership_items_attributes][19][key]': 'Tennis', 'network_membership[network_membership_items_attributes][19][value]': '', 'network_membership[network_membership_items_attributes][20][key]': 'General', 'network_membership[network_membership_items_attributes][20][value]': '', 'commit': 'Update', }, boundary='----WebKitFormBoundary' + generate_random_string( 16, 16, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'), ) headers['Content-Type'] = multipart_encoder.content_type g_var.logger.info("发布个人简介的链接...") url_link = 'https://www.sbnation.com/users/' + userData[ 'username'] + '/update_profile' html = requestsW.post(url_link, proxies=ip_proxy("en"), data=multipart_encoder, headers=headers, timeout=g_var.TIMEOUT) if html == -1: return html if html.status_code != 200: g_var.logger.info('链接发布失败。。。') g_var.logger.info(html.text) return -2 try: url = 'https://www.sbnation.com/users/' + userData['username'] sql = "INSERT INTO sbnation_com_article(url, user_id) VALUES('" + url + "', '" + str( userData["id"]) + "');" last_row_id = MysqlHandler().insert(sql) g_var.logger.info(last_row_id) if last_row_id != -1: g_var.logger.info('链接发送成功!' + userData['username']) return 0 else: g_var.ERR_CODE = 2004 g_var.ERR_MSG = "数据库插入用户注册数据失败..." g_var.logger.error("数据库插入用户注册数据失败...") return 1 except Exception as e: g_var.logger.info(e) g_var.ERR_CODE = 2004 g_var.ERR_MSG = "数据库插入用户注册数据异常..." g_var.logger.error("数据库插入用户注册数据异常...") return 1
def __register_one(self, Session, present_website: str, email_and_passwd): """ 注册一个账户 Args: Session:Session对象 present_website:当前网站名,用于数据库表名 email_and_passwd:邮箱账户和密码,email_and_passwd[0]是邮箱,[1]是密码 Returns: 注册成功返回注册数据字典对象registerData,需要包含user_id, username, password, email user_id这样获取:(示例) # 将注册的账户写入数据库(sql自己写,这边只是个示例) sql = "INSERT INTO "+present_website+"(username, password, mail, status) VALUES('" + name + \ "', '" + psd + "', '" + email_and_passwd[0] + "', '" + str(0) + "');" last_row_id = MysqlHandler().insert(sql) if last_row_id != -1: registerData["id"] = last_row_id return registerData else: g_var.logger.error("数据库插入用户注册数据失败") return 0 注册失败返回状态码 0:更换email 返回0 或其他错误,但是激活失败或插入数据库失败 -1:表示requests请求页面失败,需要更换代理 -2:注册失败,可能是邮箱密码不符合要求、或ip被封等原因,需要排查 """ user = project_util.generate_random_string(12, 16) pwd = project_util.generate_random_string(10, 12) email_list = email_and_passwd if email_list == -1: g_var.SPIDER_STATUS = 2 g_var.ERR_MSG = g_var.ERR_MSG + "|_|NO email" g_var.logger.info("NO email") return 0 verify_email = Session.get( "https://www.diigo.com/user_mana2/check_email?email=" + email_list[0], timeout=g_var.TIMEOUT, headers=self.headers, proxies=Session.proxies) # 验证邮箱是否可用 verify_user = Session.get( "https://www.diigo.com/user_mana2/check_name?username="******"1": g_var.SPIDER_STATUS = 2 g_var.ERR_MSG = g_var.ERR_MSG + "|_|账号密码或邮箱已经被注册" g_var.logger.info("账号密码或邮箱已经被注册") return 0 # time.sleep(3) google_captchas = google_captcha( "", "6Ld23sMSAAAAALfyXkI9d0nHmzOH9jZZNuh66nql", "https://www.diigo.com/sign-up?plan=free") if google_captchas == -1: g_var.SPIDER_STATUS = 2 g_var.ERR_MSG = g_var.ERR_MSG + "|_|谷歌打码失败" g_var.logger.info("谷歌打码失败") return -2 res = requestsW.get("https://www.diigo.com/", headers=self.headers, proxies=Session.proxies) # 打开首页 if res == -1: return res cookies = res.cookies.get_dict() i = 0 while i < g_var.ERR_COUNT: i += 1 try: Session.proxies = ip_proxy() res = requests.get("https://www.diigo.com/sign-up?plan=free", headers=self.headers, cookies=cookies, proxies=Session.proxies, verify=False) user_input = re.search('id="username" name="(\w{32})">', res.text) email_input = re.search('id=\'email\' name="(\w{32})">', res.text) pwd_input = re.search('id=\'password\' name="(\w{32})"', res.text) if not user_input and email_input and pwd_input: # TODO 获取不到参数 return "注册无法打开网页" else: user_input = user_input.group(1) email_input = email_input.group(1) pwd_input = pwd_input.group(1) data = { "plan": "free", "g-recaptcha-response": google_captchas, user_input: user, email_input: email_and_passwd[0], pwd_input: pwd, } self.headers["X-Requested-With"] = "XMLHttpRequest" self.headers[ "Referer"] = "https://www.diigo.com/sign-up?plan=free" self.headers[ "Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8" res = requests.post( "https://www.diigo.com/user_mana2/register_2", headers=self.headers, cookies=cookies, data=data, proxies=Session.proxies, verify=False) print(res.json()) if project_util.dictExistValue(res.json(), "status"): if res.json()["status"] == 1: cookies.update(res.cookies.get_dict()) savec = cookies res = requestsW.post( "https://www.diigo.com/user_mana2/resend_verify", cookies=cookies, headers=self.headers, data={"email": email_and_passwd[0]}, proxies=Session.proxies) print("重新发送邮箱:", res.text) emailinfo = EmailVerify( email_and_passwd[0], email_and_passwd[1], 'href="(https://www.diigo.com/user_mana2/register_verify/\w{32})"' ).execute_Start() print("这里是邮箱参数:", emailinfo) if emailinfo["data"] != -1: Session = requestsW.session() res = Session.get(emailinfo["data"], headers=self.headers, proxies=Session.proxies, cookies=cookies) sql = """INSERT INTO %s (username, password, mail, status, cookie) VALUES("%s", "%s", "%s", "%s", "%s");""" % ( "diigo_com", user, pwd, email_and_passwd[0], 0, savec) g_var.logger.info(sql) last_row_id = MysqlHandler().insert(sql) if last_row_id != -1: registerData = { "username": user, "password": pwd, "email": email_and_passwd[0], "cookie": savec, } registerData["id"] = int(last_row_id) return registerData return { "user": user, "pwd": pwd, "email": email_and_passwd[0], "cookies": Session.cookies.get_dict() } # if project_util.dictExistValue(res.cookies.get_dict(),"diigoandlogincookie"): # 注册成功并登陆cookie # saveCookie = str(Session.cookies.get_dict()) # # print({"user": user, "pwd": pwd, "email": email_and_passwd[0], "cookies": saveCookie}) # return {"user": user, "pwd": pwd, "email": email_and_passwd[0], "cookies": saveCookie} elif res.json()["status"] == -2: if "captcha error" in res.json()["status"]: g_var.SPIDER_STATUS = 2 g_var.ERR_MSG = g_var.ERR_MSG + "|_|谷歌打码失败" g_var.logger.info("谷歌打码失败") return -2 return -2 except Exception as e: res = requestsW.get("https://www.diigo.com/", headers=self.headers, proxies=Session.proxies, verify=False) # 打开首页 cookies = res.cookies.get_dict() g_var.logger.info(e) g_var.logger.info("正在换ip", e) return 0
def __register_one(self, present_website): """ 注册一个账户,需要实现注册、激活、并将注册数据存入数据库的功能 Args: Session:Session对象 present_website:当前网站名,用于数据库表名 email_and_passwd:邮箱账户和密码,email_and_passwd[0]是邮箱,[1]是密码 Returns: 注册成功返回注册数据字典对象registerData,需要包含id, username, password, email, cookie(在访问激活链接时能取到,\ 取不到返回空) user_id这样获取:(示例) # 将注册的账户写入数据库(sql自己写,这边只是个示例) sql = "INSERT INTO "+present_website+"(username, password, mail, status, cookie) VALUES('" + \ username + "', '" + password + "', '" + email + "', '" + str(0) + cookie + "');" last_row_id = MysqlHandler().insert(sql) if last_row_id != -1: registerData["user_id"] = last_row_id return registerData else: g_var.logger.error("数据库插入用户注册数据失败") return 0 注册失败返回状态码 0:数据库存储失败 -1:连续代理错误或页面发生改变等取不到关键数据等,需要停止程序 -2:注册失败,可能是打码出错等原因 """ g_var.logger.info('register......') headers = generate_headers(0) if headers == -1: return -1 g_var.logger.info('session_id......') session_id = get_session_id() if session_id == -1: return -1 elif session_id == -2: return -2 googlekey = '6LefyhkTAAAAANpeEKwwgimNneiKWXRQtEqFZbat' captcha_value = google_captcha( "", googlekey, 'https://auth.voxmedia.com/signup?return_to=https://www.sbnation.com/' ) if captcha_value == -1: return -2 headers['cookie'] = session_id username = generate_random_string(8, 12) password = generate_random_string(10, 14) community_id = random.randint(210, 299) g_var.logger.info('community_id.....') g_var.logger.info(community_id) email = username + '@hotmail.com' registerData = { 'g-recaptcha-response': captcha_value, 'user[username]': username, 'user[password]': password, 'user[email]': email, 'user[newsletter]': 'false', 'community_id': community_id, } g_var.logger.info('开始提交注册信息...') url_login = '******' html = requestsW.post(url_login, proxies=ip_proxy("en"), data=registerData, headers=headers, timeout=g_var.TIMEOUT) if html == -1: return html try: g_var.logger.info(html.text) res_data = json.loads(html.text) except Exception as e: g_var.logger.info(e) g_var.logger.info('注册失败,返回信息解析失败。。。') g_var.logger.info(html.text) return -2 if not res_data['success']: g_var.logger.info('注册失败。。。') g_var.logger.info(html.text) return -2 try: sql = "INSERT INTO " + present_website + "(username, password, mail) VALUES('" + \ username + "', '" + password + "', '" + email + "');" last_row_id = MysqlHandler().insert(sql) g_var.logger.info(last_row_id) if last_row_id != -1: g_var.logger.info('注册成功!' + username) userData = { 'id': last_row_id, 'username': username, 'password': password, } return userData else: g_var.ERR_CODE = 2004 g_var.ERR_MSG = "数据库插入用户注册数据失败..." g_var.logger.error("数据库插入用户注册数据失败...") return 0 except Exception as e: g_var.logger.info(e) g_var.ERR_CODE = 2004 g_var.ERR_MSG = "数据库插入用户注册数据异常..." g_var.logger.error("数据库插入用户注册数据异常...") return 0
def register_one(Session=None) -> dict: MysqlHandler().startDB() if Session == None: Session = requests.session() Session.proxies = ip_proxy() res = requestsW.get("https://www.diigo.com/", headers=headers, proxies=ip_proxy(), verify=False) #打开首页 cookies = res.cookies.get_dict() print("这里是cookies", cookies) str_cookies = str(res.cookies.get_dict()) cookies = eval(str_cookies) user = project_util.generate_random_string(12, 16) pwd = project_util.generate_random_string(10, 12) email_and_passwd = get_email("https://www.diigo.com") if email_and_passwd == -1: return "NO email" else: print("这里是邮箱", email_and_passwd) verify_user = requestsW.get( "https://www.diigo.com/user_mana2/check_name?username="******"https://www.diigo.com/user_mana2/check_email?email=" + email_and_passwd[0], cookies=cookies, headers=headers, proxies=Session.proxies, verify=False) #验证邮箱是否可用 if not verify_user.text == verify_email.text == "1": print("错误") return "账号密码或邮箱已经被注册" # time.sleep(3) google_captchas = google_captcha( "", "6Ld23sMSAAAAALfyXkI9d0nHmzOH9jZZNuh66nql", "https://www.diigo.com/sign-up?plan=free") # google_captchas ="google_captchas" if google_captchas == -1: return "谷歌打码失败" # requestsW.get("https://www.diigo.com/interact_api/load_user_premium_info",headers=headers,cookies=cookies,proxies=Session.proxies,verify=False)#必须访问 i = 0 while i < 20: try: Session.proxies = ip_proxy() res = requests.get("https://www.diigo.com/sign-up?plan=free", headers=headers, cookies=cookies, proxies=Session.proxies, verify=False) user_input = re.search('id="username" name="(\w{32})">', res.text) email_input = re.search('id=\'email\' name="(\w{32})">', res.text) pwd_input = re.search('id=\'password\' name="(\w{32})"', res.text) if not user_input and email_input and pwd_input: # TODO 获取不到参数 return "注册无法打开网页" else: user_input = user_input.group(1) email_input = email_input.group(1) pwd_input = pwd_input.group(1) data = { "plan": "free", "g-recaptcha-response": google_captchas, user_input: user, email_input: email_and_passwd[0], pwd_input: pwd, } headers["X-Requested-With"] = "XMLHttpRequest" headers["Referer"] = "https://www.diigo.com/sign-up?plan=free" headers[ "Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8" print("准备提交") print(cookies) res = requests.post("https://www.diigo.com/user_mana2/register_2", headers=headers, cookies=cookies, data=data, proxies=Session.proxies, verify=False) print(res.json()) if project_util.dictExistValue(res.json(), "status"): if res.json()["status"] == 1: cookies.update(res.cookies.get_dict()) savec = cookies res = requestsW.post( "https://www.diigo.com/user_mana2/resend_verify", cookies=cookies, headers=headers, data={"email": email_and_passwd[0]}, proxies=Session.proxies) print("重新发送邮箱:", res.text) emailinfo = MyEmail( email_and_passwd[0], email_and_passwd[1], 'href="(https://www.diigo.com/user_mana2/register_verify/\w{32})"' ).execute_Start() print("这里是邮箱参数:", emailinfo) if emailinfo["data"] != -1: Session = requestsW.session() res = Session.get(emailinfo["data"], headers=headers, proxies=Session.proxies, cookies=cookies) sql = """INSERT INTO %s (username, password, mail, status, cookie) VALUES("%s", "%s", "%s", "%s", "%s");""" % ( "diigo_com", user, pwd, email_and_passwd[0], 0, savec) g_var.logger.info(sql) last_row_id = MysqlHandler().insert(sql) if last_row_id != -1: registerData = { "username": user, "password": pwd, "email": email_and_passwd[0], } registerData["user_id"] = last_row_id return registerData return { "user": user, "pwd": pwd, "email": email_and_passwd[0], "cookies": Session.cookies.get_dict() } # if project_util.dictExistValue(res.cookies.get_dict(),"diigoandlogincookie"): # 注册成功并登陆cookie # saveCookie = str(Session.cookies.get_dict()) # # print({"user": user, "pwd": pwd, "email": email_and_passwd[0], "cookies": saveCookie}) # return {"user": user, "pwd": pwd, "email": email_and_passwd[0], "cookies": saveCookie} return "res:" + res.text except (ConnectTimeout, ReadTimeout, ConnectionError) as e: res = requestsW.get("https://www.diigo.com/", headers=headers, proxies=Session.proxies, verify=False) # 打开首页 cookies = res.cookies.get_dict() i += 1 print(e) print("正在换ip", e)
g_var.logger = Logger('test.log', level='info').logger # 实例化一个logger对象 g_var.INTERFACE_HOST = "http://192.168.31.234:8080" g_var.UUID = "1383838438" get_global_params("scoop_it") Session = get_Session("en") url = "https://www.scoop.it/subscribe?&token=&sn=&showForm=true" # headers = { # 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36', # } # html = Session.get(url, headers=headers, timeout=g_var.TIMEOUT).text # print(html) FullName = generate_random_string(15, 20) password = generate_random_string(10, 15) email_and_passwd = get_email("scoop_it") # googlekey="6LevIjoUAAAAAEJnsStYfxxf5CEQgST01NxAwH8v" # pageurl="https://www.scoop.it/subscribe?&token=&sn=&showForm=true" # recaptcha_value = google_captcha(Session, googlekey, pageurl) recaptcha_value = input("请输入验证码:") registerData = { 'jsDetectedTimeZone': 'Asia/Shanghai', 'pc': '', 'displayName': FullName, 'shortName': FullName, 'email': email_and_passwd[0], 'password': password,
def __register_one(self, present_website, email_info, googlekey): """ 注册一个账户 Args: Session:Session对象 present_website:当前网站名,用于数据库表名 email_and_passwd:邮箱账户和密码,email_and_passwd[0]是邮箱,[1]是密码 Returns: 注册成功返回注册数据字典对象registerData,需要包含user_id, username, password, email user_id这样获取:(示例) # 将注册的账户写入数据库(sql自己写,这边只是个示例) sql = "INSERT INTO "+present_website+"(username, password, mail, status) VALUES('" + name + \ "', '" + psd + "', '" + email_and_passwd[0] + "', '" + str(0) + "');" last_row_id = MysqlHandler().insert(sql) if last_row_id != -1: registerData["user_id"] = last_row_id return registerData else: g_var.logger.error("数据库插入用户注册数据失败") return 0 注册失败返回状态码 0:注册成功,但是激活失败或插入数据库失败 -1:表示requests请求页面失败,需要更换代理 -2:注册失败,可能是邮箱密码不符合要求、或ip被封等原因,需要排查 """ url_register_one = 'https://login.ex.co/api/signup' headers = generate_headers(0) headers['Referer'] = 'https://login.ex.co/signup' if headers == -1: g_var.logger.info("获取headers失败...") return -1 captcha_value = google_captcha("", googlekey, url_register_one) if captcha_value == -1: return -2 registerData = generate_register_data(email_info, captcha_value) g_var.logger.info("提交注册中...") html = requestsW.post(url_register_one, proxies=ip_proxy("en"), json=registerData, headers=headers, timeout=g_var.TIMEOUT) if html == -1: return html if '"success":true' not in html.text: g_var.logger.info('注册失败。。。') g_var.logger.info(html.text) return -2 accessToken = re.findall('accessToken":"(.*?)"}}', html.text)[0] userId = re.findall('"UserId":"(.*?)",', html.text)[0] headers = generate_headers(1, accessToken) if headers == -1: g_var.logger.info("获取第二步注册验证的headers失败...") return -1 company = generate_random_string(10, 12) data = { "company": company, "industryType": 'Freelancer', "companySize": "", "userIntent": "" } url_register_two = 'https://login.ex.co/api/additional-data' g_var.logger.info("第二步提交注册中...") html = requestsW.post(url_register_two, proxies=ip_proxy("en"), json=data, headers=headers, timeout=g_var.TIMEOUT) if html == -1: return html if html.text != '{"success":true}': g_var.logger.info('第二步注册失败。。。') g_var.logger.info(html.text) return -2 # 将注册的账户写入数据库 try: sql = "INSERT INTO " + present_website + "(username, password, mail, cookie, userId) VALUES('" + \ registerData['firstName'] + "', '" + registerData['password'] + "', '" + email_info[0] + "', '" + accessToken + "', '" + str( userId) + "');" last_row_id = MysqlHandler().insert(sql) g_var.logger.info(last_row_id) if last_row_id != -1: g_var.logger.info('注册成功!' + registerData['firstName']) registerData["id"] = last_row_id registerData["cookie"] = accessToken registerData["userId"] = str(userId) return registerData else: g_var.ERR_CODE = 2004 g_var.ERR_MSG = "数据库插入用户注册数据失败..." g_var.logger.error("数据库插入用户注册数据失败...") return 0 except Exception as e: g_var.logger.info(e) g_var.ERR_CODE = 2004 g_var.ERR_MSG = "数据库插入用户注册数据异常..." g_var.logger.error("数据库插入用户注册数据异常...") return 0
def __postMessage(self, userData, present_website): """ 发文章 Args: Session:Session对象 loginData:用户信息,包括user_id,username,password,cookie present_website:当前网站名,用于数据库表名 Returns: 成功返回:"ok" 失败返回状态值: 1:跳出循环,重新取号 0:cookie失效,将cookie清空,跳出循环重新取号 -1:连续代理错误或页面发生改变等取不到关键数据等,需要停止程序 -2:本次出错,继续循环 """ g_var.logger.info("post article ...") headers = generate_headers(0) if headers == -1: g_var.logger.info("获取headers失败...") return -1 g_var.logger.info("article ...") article = get_new_article() if article == -1: return -2 content = get_code_content(article[1]) if content == -2: return -2 g_var.logger.info("postarticle_tok ...") uid_upwd = userData['cookie'].split('|_|') postarticle_tok = get_postarticle_tok(uid_upwd[0]) if postarticle_tok == -1: return -1 elif postarticle_tok == -2: return -2 g_var.logger.info("new_article_Id ...") new_article_Id = get_newarticle_Id(uid_upwd, article[0], headers) if new_article_Id == -1: return -1 elif new_article_Id == -2: return -2 elif new_article_Id == 1: return 1 headers['Origin'] = 'https://www.liveinternet.ru' headers[ 'Referer'] = 'https://www.liveinternet.ru/journal_post.php?journalid=' + uid_upwd[ 0] headers['Cookie'] = 'bbuserid=' + uid_upwd[ 0] + '; bbpassword='******'action': 'newpost', 'parsing': '', 'journalid': uid_upwd[0], 'backurl': '', 'selectforum': '/journal_post.php?journalid=' + uid_upwd[0], 'headerofpost': article[0], 'mode': str(0), 'status': 'Use these controls to insert vBcode', 'LiNewPostForm': content, # 文章内容 'tags': article[-1], # 标签 'uploader_count': str(0), 'music': '', 'mood': '', 'attachfile1': ("", '', 'application/octet-stream'), 'MAX_FILE_SIZE': '', 'nocomment': str(0), 'commentsubscribe': 'yes', 'parseurl': 'yes', 'autosave_postid': new_article_Id, # blog ID 'close_level': str(0), 'tok': postarticle_tok, }, boundary='------WebKitFormBoundary' + generate_random_string( 16, 16, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'), ) headers['Content-Type'] = multipart_encoder.content_type g_var.logger.info("正在发布文章 ...") url_article = 'https://www.liveinternet.ru/journal_addpost.php' html = requestsW.post(url_article, proxies=ip_proxy("en"), data=multipart_encoder, headers=headers) if html == -1: return -1 # 发布成功与否验证 prove = 'Вы добавили сообщение в Ваш дневник' if prove not in html.text: g_var.ERR_CODE = 5000 g_var.ERR_MSG = "文章发送失败,IP异常等原因..." g_var.logger.info('文章发送失败,IP异常等原因...') return 0 del headers['Origin'] 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' g_var.logger.info("正在获取新文章id ...") url_new_article = 'https://www.liveinternet.ru/users/' + userData[ 'username'] + '/blog/' res = requestsW.get(url_new_article, proxies=ip_proxy("en"), headers=headers) if res == -1: return -1 article_url = re.search( 'https://www.liveinternet.ru/users/' + userData['username'].lower() + '/post(.*?)/', res.text) if not article_url: ('获取新发布文章url失败。。。') return 0 try: new_article_url = article_url.group() sql = "INSERT INTO liveinternet_ru_article(url, keyword, user_id) VALUES('" + new_article_url + "', '" + article[ 0] + "', '" + str(userData["id"]) + "');" last_row_id = MysqlHandler().insert(sql) g_var.logger.info(last_row_id) if last_row_id != -1: g_var.logger.info('文章成功!' + userData['username']) return 'ok' else: g_var.ERR_CODE = 2004 g_var.ERR_MSG = "数据库插入用户注册数据失败..." g_var.logger.error("数据库插入用户注册数据失败...") return 0 except Exception as e: g_var.logger.info(e) g_var.ERR_CODE = 2004 g_var.ERR_MSG = "数据库插入用户注册数据异常..." g_var.logger.error("数据库插入用户注册数据异常...") return 0
def __postMessage(self, Session, loginData, present_website): """ 发文章 Args: Session:Session对象 loginData:用户信息,包括user_id,username,password,cookie present_website:当前网站名,用于数据库表名 Returns: 成功返回状态值:loginData 失败返回状态值: -1:表示requests请求页面失败,需要更换代理 -2:页面发生改变,获取不到页面上的一些token值 0:数据库插入更新等错误 """ g_var.logger.info("post link...") headers = generate_headers(1, loginData['csrftoken']) if headers == -1: g_var.logger.info("获取注册headers失败...") return -1 cookie = 'csrftoken=' + loginData['csrftoken'] + '; c=' + loginData['c'] headers['Cookie'] = cookie biog = get_new_link() if biog == -1: return -1 try: num = string.ascii_letters + string.digits i = random.choice(num) variables = '{"input_0":{"country":null,"birthyear":null,"menuItems":[{"itemType":"STREAM","hidden":false,"inDropdown":false},{"itemType":"UPLOADS","hidden":false,"inDropdown":false},{"itemType":"FAVORITES","hidden":false,"inDropdown":false},{"itemType":"LISTENS","hidden":false,"inDropdown":false}],"displayName":"' + loginData[ 'username'] + '","biog":"' + biog + '","city":null,"gender":null,"brandedProfile":{"backgroundTiled":null,"backgroundColor":null},"clientMutationId":"' + i + '"}}' multipart_encoder = MultipartEncoder( fields={ 'id': i, 'query': 'mutation ChangeProfileMutation($input_0:ChangeProfileMutationInput!) {changeProfile(input:$input_0) {viewer {me {percentageComplete,displayName,biog,city,countryCode,country,gender,birthYear,brandedProfile {backgroundTiled,backgroundPicture {urlRoot},backgroundColor},picture {urlRoot,primaryColor},coverPicture {urlRoot,primaryColor},_profileNavigation3Jqt8o:profileNavigation(showHidden:true) {menuItems {__typename,...F0,...F1,...F2}},profileNavigation {menuItems {__typename,...F0,...F1,...F2}},id},id},clientMutationId}} fragment F0 on NavigationItemInterface {inDropdown,__typename} fragment F1 on HideableNavigationItemInterface {hidden,__typename} fragment F2 on PlaylistNavigationItem {count,playlist {id,name,slug}}', 'variables': variables, 'picture': 'undefined', 'coverPicture': 'undefined', 'backgroundPicture': 'undefined', '_onProgress': 'function(e,n){t.forEach(function(t){t(e,n)})}', '_aborter': '[object Object]', '_useUploadServers': 'undefined', }, boundary='------WebKitFormBoundary' + generate_random_string( 16, 16, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'), ) headers['Content-Type'] = multipart_encoder.content_type except Exception as e: g_var.ERR_CODE = 5000 g_var.ERR_MSG = "推送个人链接数据生成中出现异常..." g_var.logger.info("推送个人链接数据生成中出现异常...") g_var.logger.info(e) return -2 url_link = 'https://www.mixcloud.com/graphql' g_var.logger.info("推送链接中...") html = Session.post(url_link, data=multipart_encoder, headers=headers, timeout=g_var.TIMEOUT) if html == -1: return html if biog in html.text: g_var.logger.info("链接发送成功!" + loginData["username"]) # 将链接、用户存入mixcloud_com_article表 url = 'https://www.mixcloud.com/' + loginData['username'] + '/' sql = "INSERT INTO mixcloud_com_article(url, user_id) VALUES('" + url + "', '" + str( loginData['id']) + "');" if g_var.insert_article_lock.acquire(): last_row_id = MysqlHandler().insert(sql) g_var.insert_article_lock.release() if last_row_id != -1: g_var.logger.info("insert article OK") else: g_var.logger.error("数据库插入链接错误!") return 0 return loginData else: g_var.logger.error("链接发送失败!..." + str(html.status_code)) g_var.ERR_CODE = 5000 g_var.ERR_MSG = g_var.ERR_MSG + "|_|" + "链接发送失败,未知错误!" return 0
def __register_one(self, Session, present_website: str, email_and_passwd): """ 注册一个账户,需要实现注册、激活、并将注册数据存入数据库的功能 Args: Session:Session对象 present_website:当前网站名,用于数据库表名 email_and_passwd:邮箱账户和密码,email_and_passwd[0]是邮箱,[1]是密码 Returns: 注册成功返回注册数据字典对象registerData,需要包含id, username, password, email, cookie(在访问激活链接时能取到,\ 取不到返回空) user_id这样获取:(示例) # 将注册的账户写入数据库(sql自己写,这边只是个示例) sql = "INSERT INTO "+present_website+"(username, password, mail, status, cookie) VALUES('" + \ username + "', '" + password + "', '" + email + "', '" + str(0) + cookie + "');" last_row_id = MysqlHandler().insert(sql) if last_row_id != -1: registerData["user_id"] = last_row_id return registerData else: g_var.logger.error("数据库插入用户注册数据失败") return 0 注册失败返回状态码 0:某些报错需要跳出while循环,更换邮箱 -1:连续代理错误或页面发生改变等取不到关键数据等,需要停止程序 -2:注册失败,可能是打码出错等原因,邮箱可以继续使用(邮箱资源成本较高,因此要确保注册成功后再更换邮箱),不跳出循环 """ FullName = generate_random_string(15, 20) password = generate_random_string(10, 15) # googlekey = "6LevIjoUAAAAAEJnsStYfxxf5CEQgST01NxAwH8v" # pageurl = "https://www.scoop.it/subscribe?&token=&sn=&showForm=true" # recaptcha_value = google_captcha(Session, googlekey, pageurl) recaptcha_value = input("请输入验证码:") registerData = { 'jsDetectedTimeZone': 'Asia/Shanghai', 'pc': '', 'displayName': FullName, 'shortName': FullName, 'email': email_and_passwd[0], 'password': password, 'avatar': '', 'upload-image-original-url': '', 'job': 'My personal brand or blog', 'g-recaptcha-response': recaptcha_value, 'subscribe': '' } headers = { 'content-type': 'application/x-www-form-urlencoded', 'cookie': 'messagesUtk=beaaffd5ab3d4039b7e27015e4203fda;', 'origin': 'https://www.scoop.it', 'referer': 'https://www.scoop.it/subscribe?&token=&sn=&showForm=true', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36', } url = "https://www.scoop.it/subscribe?&token=&sn=&showForm=true" result = Session.post(url, headers=headers, data=registerData, timeout=g_var.TIMEOUT) if result == -1: g_var.logger.error("提交注册信息超时") return -1 g_var.logger.info("提交注册..." + result.text) re_text = '(https://www.scoop.it/confirm\?.*?)" ' email_verify_obj = EmailVerify(email_and_passwd[0], email_and_passwd[1], re_text) verify_url = account_activation(Session, email_verify_obj) result = Session.get(url=verify_url, headers=headers, timeout=g_var.TIMEOUT) if result == -1: g_var.logger.error("访问激活链接超时") return -1 # 获取cookie # 也就是这边取不到cookie,还需要填写自己感兴趣的领域??? print(result.cookies.get_dict()) cookie = str(result.cookies.get_dict()) sql = "INSERT INTO " + present_website + "(username, password, mail, status, cookie) VALUES('" + FullName + \ "', '" + password + "', '" + email_and_passwd[0] + "', '" + str(0) + "', '" +cookie + "');" last_row_id = MysqlHandler().insert(sql) if last_row_id != -1: registerData = dict() registerData["user_id"] = last_row_id return registerData else: g_var.logger.error("数据库插入用户注册数据失败") return 0
def __register_one(self, Session): """ 注册一个账户 Args: Session:Session对象 present_website:当前网站名,用于数据库表名 email_and_passwd:邮箱账户和密码,email_and_passwd[0]是邮箱,[1]是密码 Returns: 注册成功返回注册数据字典对象registerData,需要包含user_id, username, password, email user_id这样获取:(示例) # 将注册的账户写入数据库(sql自己写,这边只是个示例) sql = "INSERT INTO "+present_website+"(username, password, mail, status) VALUES('" + name + \ "', '" + psd + "', '" + email_and_passwd[0] + "', '" + str(0) + "');" last_row_id = MysqlHandler().insert(sql) if last_row_id != -1: registerData["user_id"] = last_row_id return registerData else: g_var.logger.error("数据库插入用户注册数据失败") return 0 注册失败返回状态码 0:注册成功,但是激活失败或插入数据库失败 -1:表示requests请求页面失败,需要更换代理 -2:注册失败,可能是邮箱密码不符合要求、或ip被封等原因,需要排查 """ g_var.logger.info("register...") csrftoken = get_csrf(Session) if csrftoken == -1: return -1 elif csrftoken == -2: return -2 headers = generate_headers(0, csrftoken) if headers == -1: g_var.logger.info("获取注册headers失败...") return -1 try: username = generate_random_string(8, 12) password = generate_random_string(10, 14) email = username + '@hotmail.com' multipart_encoder = MultipartEncoder( fields={ 'email': email, 'password': password, 'username': username, 'ch': 'y', }, boundary='----WebKitFormBoundary' + generate_random_string( 16, 16, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'), ) headers['Content-Type'] = multipart_encoder.content_type except Exception as e: g_var.ERR_CODE = 5000 g_var.ERR_MSG = "注册数据生成中出现异常..." g_var.logger.info("注册数据生成中出现异常...") g_var.logger.info(e) return -2 url_register = 'https://www.mixcloud.com/authentication/email-register/' g_var.logger.info("提交注册中...") html = Session.post(url_register, data=multipart_encoder, headers=headers, timeout=g_var.TIMEOUT) if html == -1: return html try: text = json.loads(html.text) if not text['success']: g_var.logger.info(text) return -2 except Exception as e: g_var.logger.info(e) g_var.ERR_CODE = 5000 g_var.ERR_MSG = "此次注册未完成安全检查(IP问题)..." g_var.logger.error("此次注册未完成安全检查(IP问题)") return -2 try: cookie = html.headers['Set-Cookie'] csrftoken = re.findall('csrftoken=(.*?);', cookie) c = re.findall('secure, c=(.*?);', cookie) sql = "insert into mixcloud_com (id, username, password, mail) values('{0}', '{1}', '{2}', '{3}');" \ .format(str(text['authentication']['currentUser']['id']), username, password, email) last_row_id = MysqlHandler().insert(sql) userData = {} if last_row_id != -1: userData["id"] = last_row_id userData["username"] = username userData["password"] = password userData["csrftoken"] = csrftoken[0] userData["c"] = c[0] return userData else: g_var.ERR_CODE = 2004 g_var.ERR_MSG = "数据库插入失败..." g_var.logger.error("数据库插入失败") return 0 except Exception as e: g_var.logger.info(e) g_var.ERR_CODE = 2004 g_var.ERR_MSG = "数据库插入失败..." g_var.logger.error("数据库插入失败") return 0