Esempio n. 1
0
class CookiesGenerator(object):
    def __init__(self, website='default'):
        """
        父类, 初始化一些对象
        :param website: 名称
        :param browser: 浏览器, 若不使用浏览器则可设置为 None
        """
        self.website = website
        self.cookies_db = RedisClient('cookies', self.website)
        self.accounts_db = RedisClient('accounts', self.website)

    def new_cookies(self, username, password):
        """
        新生成Cookies,子类一定需要重写
        :param username: 用户名
        :param password: 密码
        :return:
        """
        raise NotImplementedError

    def process_cookies(self, cookies):
        """
        处理Cookies
        :param cookies:
        :return:
        """
        dict = {}
        for cookie in cookies:
            dict[cookie['name']] = cookie['value']
        return dict

    def run(self):
        """
        运行, 得到所有账户, 然后顺次模拟登录
        :return:
        """
        accounts_usernames = self.accounts_db.usernames()
        cookies_usernames = self.cookies_db.usernames()

        for username in accounts_usernames:
            if not username in cookies_usernames:
                password = self.accounts_db.get(username)
                print('正在生成Cookies', '账号', username, '密码', password)
                result = self.new_cookies(username, password)
                # 成功获取
                if result.get('status') == 1:
                    # cookies = self.process_cookies(result.get('content'))
                    cookies = result.get('content')
                    print('成功获取到Cookies', cookies)
                    if self.cookies_db.set(username, json.dumps(cookies)):
                        print('成功保存Cookies')
                # 密码错误,移除账号
                elif result.get('status') == 2:
                    print("reason: {}".format(result.get('content')))
                    if self.accounts_db.delete(username):
                        print('成功删除账号: {}'.format(username))
                else:
                    print("其他错误: {}".format(result.get('content')))
        else:
            print('所有账号都已经成功获取Cookies')
Esempio n. 2
0
def set_robo_account(fp):
    conn = RedisClient('accounts', 'robo')
    with open(fp, 'r') as fp:
        robo_accounts = json.load(fp)

    for account in robo_accounts:
        result = conn.set(account['username'], account['password'])
        print('账号', account['username'], '录入成功' if result else '录入失败')
Esempio n. 3
0
 def __init__(self, website='default'):
     """
     父类, 初始化一些对象
     :param website: 名称
     """
     self.website = website
     self.cookies_db = RedisClient('cookies', self.website)
     self.accounts_db = MongoCli()
Esempio n. 4
0
 def __init__(self, website):
     """
     初始化一些对象
     :param website: 网站名称
     """
     self.website = website
     self.cookies_db = RedisClient('cookies', self.website)
     self.accounts_db = RedisClient('accounts', self.website)
Esempio n. 5
0
 def __init__(self, website='default'):
     """
     父类, 初始化一些对象
     :param website: 名称
     :param browser: 浏览器, 若不使用浏览器则可设置为 None
     """
     self.website = website
     self.cookies_db = RedisClient('cookies', self.website)
     self.accounts_db = RedisClient('accounts', self.website)
Esempio n. 6
0
 def __init__(self,website='default'):
     '''
     检测模块
     获取新增用户cookies,保存
     :param website: 名称
     '''
     self.website = website
     self.cookies_db = RedisClient('cookies',self.website)
     self.accounts_db = RedisClient('accounts',self.website)
     self.driver = webdriver.Chrome()
Esempio n. 7
0
class Spider():
    def __init__(self):
        self.redis = RedisClient()

    def getHTML(self):
        proxy = self.redis.random()
        proxies = {
            'http': 'http://' + proxy,
            'https': 'https://' + proxy,
        }
        try:
            r = requests.get(url,
                             allow_redirects=False,
                             headers=headers,
                             proxies=proxies,
                             timeout=30)
            print('正在使用:', proxy)
            if r.status_code == 200:
                header = r.headers
                print(header)
                snuid = re.findall('(SNUID=.*?;)', header['Set-Cookie'])
                print(snuid)
                if len(snuid) != 0:
                    self.redis.push(snuid[0])
                    print('Redis插入:', snuid[0])
                    while snuid != None:
                        self.circle(proxy)
                        time.sleep(SLEEPTIME)
                    else:
                        self.redis.decrease(proxy)
                else:
                    self.redis.decrease(proxy)
        except TimeoutError:
            pass

    def circle(self, proxy):
        proxies = {
            'http': 'http://' + proxy,
            'https': 'https://' + proxy,
        }
        try:
            r = requests.get(url,
                             allow_redirects=False,
                             headers=headers,
                             proxies=proxies)
            print('循环代理:', proxy)
            if r.status_code == 200:
                header = r.headers
                print(header)
                snuid = re.findall('(SNUID=.*?;)', header['Set-Cookie'])
                if len(snuid) != 0:
                    self.redis.push(snuid[0])
                    print('Redis插入:', snuid[0])
                    return snuid
                else:
                    snuid = None
                    return snuid
        except:
            snuid = None
            return snuid
Esempio n. 8
0
    def __init__(self, website='default'):
        '''
        父类,初始化一些对象
        :param website: 名称
        :param browser: 浏览器,若不使用浏览器则可设置为 None
        '''

        self.website = website
        self.cookies_db = RedisClient('cookies', self.website)
        self.accounts_db = RedisClient('accounts', self.website)
        self.init_browser()
Esempio n. 9
0
 def __init__(self, website='default'):
     """
     父类, 初始化一些对象
     :param website: 名称
     :param browser: 浏览器, 若不使用浏览器则可设置为 None
     """
     # 浏览器对象
     self.website = website
     # Redis 数据库连接对象---cookies 池
     self.cookies_db = RedisClient('cookies', self.website)
     # Redis 数据库连接对象--- 用户池
     self.accounts_db = RedisClient('accounts', self.website)
     # 初始化浏览器设置
     self.init_browser()
Esempio n. 10
0
class XQCookiesGenerator(object):
    def __init__(self, website):
        """
        初始化一些对象
        :param website: 网站名称
        """
        self.website = website
        self.cookies_db = RedisClient('cookies', self.website)
        self.accounts_db = RedisClient('accounts', self.website)

    #def __del__(self):
    #    self.browser.close()

    def run(self):
        """
        运行, 得到所有账户, 然后顺次模拟登录
        :return:
        """
        accounts_usernames = self.accounts_db.usernames()
        cookies_usernames = self.cookies_db.usernames()

        for username in accounts_usernames:
            if not username in cookies_usernames:
                password = self.accounts_db.get(username)
                print('正在生成Cookies', '账号:', username, '密码:', password)
                cookie = self.new_cookies(username, password)
                # 成功获取
                if cookie:
                    print('成功获取到Cookies', cookie)
                    if self.cookies_db.set(username, json.dumps(cookie)):
                        print('成功保存Cookies\n')
                else:
                    print('Cookies获取失败\n')
                time.sleep(10)
                cookie = None

    def new_cookies(self, username, password):
        """
        生成Cookies
        :param username: 用户名
        :param password: 密码
        :return: 用户名和Cookies
        """
        return CookiesGenerate(username, password).main()
Esempio n. 11
0
class ValidTester(object):
    def __init__(self, website='default'):
        self.website = website
        self.cookies_db = RedisClient('cookies', self.website)
        self.accounts_db = RedisClient('accounts', self.website)

    def test(self, username, cookies):
        raise NotImplementedError

    def run(self):
        cookies_groups = self.cookies_db.all()
        for username, cookies in cookies_groups.items():
            self.test(username, cookies)
Esempio n. 12
0
class CookiesGenerator(object):
    def __init__(self, website='default'):
        """
        父类, 初始化一些对象
        :param website: 名称
        """
        self.website = website
        self.cookies_db = RedisClient('cookies', self.website)
        self.accounts_db = RedisClient('accounts', self.website)

    def new_cookies(self, username, password):
        """
        新生成Cookies,子类需要重写
        :param username: 用户名
        :param password: 密码
        :return:
        """
        raise NotImplementedError

    def run(self):
        """
        运行, 得到所有账户, 然后顺次模拟登录
        :return:
        """
        accounts_usernames = self.accounts_db.usernames()
        cookies_usernames = self.cookies_db.usernames()

        for username in accounts_usernames:
            if not username in cookies_usernames:
                password = self.accounts_db.get(username)
                print('正在生成Cookies', '账号', username, '密码', password)
                result = self.new_cookies(username, password)
                cookies = result
                print('成功获取到Cookies', cookies)
                if self.cookies_db.set(username, json.dumps(cookies)):
                    print('成功保存Cookies')
        else:
            print('所有账号都已经成功获取Cookies')
Esempio n. 13
0
class CookiesGenerator(object):
    def __init__(self, website='default'):

        self.website = website
        self.cookies_db = RedisClient('cookies', self.website)
        self.accounts_db = RedisClient('accounts', self.website)
    
    def new_cookies(self, *args):

        raise NotImplementedError

    def run(self):

        accounts_usernames = self.accounts_db.usernames()

        for username in accounts_usernames:

            if username:
                password = self.accounts_db.get(username)
                print('正在生成Cookies', '账号', username, '密码', password)
                result = self.new_cookies(username, password)
            else:
                print('正在生成Cookies')
                result = self.new_cookies()
            # 成功获取
            if result.get('status') == 1:
                content_data = result.get('content')
                print('成功获取到随机请求头', content_data)
                if self.cookies_db.set(username, content_data):
                    print('成功保存随机请求头')
            # 密码错误,移除账号
            elif result.get('status') == 2:
                print(result.get('content'))
                if self.accounts_db.delete(username):
                    print('成功删除账号')
            else:
                print(result.get('content'))
Esempio n. 14
0
class Import(object):
    def __init__(self):
        self.conn = RedisClient('accounts', 'xueqiu')

    def set(self, account, sep='----'):
        username, password = account.split(sep)
        result = self.conn.set(username, password)
        username, password = account.split(sep)
        print('账号:%s,密码:%s' % (username, password))
        print('录入成功\n' if result else '账号已存在\n')

    def scan(self):
        accouns_path = 'accounts/' + ACCOUNTS_FILE
        accounts = pd.read_table(accouns_path, header=None)
        for account in accounts[0]:
            self.set(account)
        print('账号录入完成\n')
Esempio n. 15
0
class CookiesGenerator(object):
    def __init__(self, website='default'):
        """
        父类, 初始化一些对象
        :param website: 名称
        :param browser: 浏览器, 若不使用浏览器则可设置为 None
        """
        self.website = website
        self.cookies_db = RedisClient('cookies', self.website)
        self.accounts_db = RedisClient('accounts', self.website)
        self.init_browser()

    def __del__(self):
        #self.close()
        pass

    def init_browser(self):
        """
        通过browser参数初始化全局浏览器供模拟登录使用
        :return:
        """
        if BROWSER_TYPE == 'PhantomJS':
            caps = DesiredCapabilities.PHANTOMJS
            caps[
                "phantomjs.page.settings.userAgent"] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36'
            self.browser = webdriver.PhantomJS(
                '/Users/ahua/Desktop/phantomjs/bin/phantomjs',
                desired_capabilities=caps)
            self.browser.set_window_size(500, 1400)
        elif BROWSER_TYPE == 'Chrome':
            self.display = Display(visible=0, size=(800, 800))
            self.display.start()
            self.option = webdriver.ChromeOptions()
            self.option.add_argument('--no-sandbox')
            self.browser = webdriver.Chrome(
                executable_path=
                '/users/lichao/Toolkit/driver/chromedriver_wechat',
                chrome_options=self.option)

    def new_cookies(self, username, password):
        """
        新生成Cookies,子类需要重写
        :param username: 用户名
        :param password: 密码
        :return:
        """
        raise NotImplementedError

    def process_cookies(self, cookies):
        """
        处理Cookies
        :param cookies:
        :return:
        """
        return cookies

    def run(self):
        """
        运行, 得到所有账户, 然后顺次模拟登录
        :return:
        """
        accounts_usernames = self.accounts_db.usernames()
        # print(accounts_usernames)
        cookies_usernames = self.cookies_db.usernames()
        # print(cookies_usernames)
        for username in accounts_usernames:
            if not username in cookies_usernames:
                password = self.accounts_db.get(username)
                print('正在生成Cookies', '账号', username, '密码', password)
                result = self.new_cookies(username, password)
                # 成功获取
                if result.get('status') == 1:
                    cookies = self.process_cookies(result.get('content'))
                    print('成功获取到Cookies', cookies)
                    if self.cookies_db.set(username, json.dumps(cookies)):
                        print('成功保存Cookies')
                # 密码错误,移除账号
                elif result.get('status') == 2:
                    print(result.get('content'))
                    if self.accounts_db.delete(username):
                        print('成功删除账号')
                else:
                    print(result.get('content'))
        else:
            print('所有账号都已经成功获取Cookies')

    def close(self):
        """
        关闭
        :return:
        """
        try:
            print('Closing Browser')
            self.browser.close()
            del self.browser
            os.system('pkill -f "/users/lichao/Toolkit/driver/chromedriver"')
            os.system('pkill -f "/opt/google/chrome/chrome"')
            os.system('pkill -f "/usr/bin/google-chrome"')
        except TypeError:
            print('Browser not opened')

        try:
            print('Closing Display')
            self.display.stop()
            del self.display
        except TypeError:
            print('Display not opened')
Esempio n. 16
0
class CookiesGenerator(object):
    def __init__(self, website='default'):
        """
        父类, 初始化一些对象
        :param website: 名称
        """
        self.website = website
        self.cookies_db = RedisClient('cookies', self.website)
        self.accounts_db = MongoCli()

    def __del__(self):
        pass

    def init(self):
        """
        初始化登陆时参数信息
        :return:
        """
        pass

    def new_cookies(self, username, password=''):
        """
        新生成Cookies,子类需要重写
        :param username: 用户名
        :param password: 密码
        :return:
        """
        raise NotImplementedError

    def process_cookies(self, cookies):
        """
        处理Cookies
        :param cookies:
        :return:
        """
        dict = {}
        for cookie in cookies:
            dict[cookie['name']] = cookie['value']
        return dict

    def run(self):
        """
        运行, 得到所有账户, 然后顺次模拟登录
        :return:
        """
        accounts_usernames = self.accounts_db.usernames()
        cookies_usernames = self.cookies_db.usernames()

        for username in accounts_usernames:
            if not username in cookies_usernames:
                username = username.get('username', '')
                print('正在生成Cookies', '账号', username)
                result = self.new_cookies(username)
                # 成功获取
                if result.get('status') == 1:
                    cookies = result.get('content')
                    print('成功获取到Cookies', cookies)
                    if self.cookies_db.set(username, json.dumps(cookies)):
                        print('成功保存Cookies')
                # 密码错误,移除账号
                elif result.get('status') == 2:
                    print(result.get('content'))
                    if self.accounts_db.delete(username):
                        print('成功删除账号')
                else:
                    print(result.get('content'))
        else:
            print('所有账号都已经成功获取Cookies')
Esempio n. 17
0
# !usr/bin/env python
# -*- coding:utf-8 -*-

# @FileName:importer.py
# @Author:tian
# @Time:20/05

import requests
from cookiespool.db import RedisClient

conn = RedisClient('accounts', 'baidu')


def set(account, sep=':'):
    username, password = account.split(sep)
    result = conn.set(username, password)
    print(f'用户账号:{username},密码:{password}')
    print('登录成功' if result else '登录失败')


def scan():
    print('请输入账号密码,按exit退出:')
    while True:
        account = input()
        if account == 'exit':
            break
        set(account)


if __name__ == '__main__':
    scan()
Esempio n. 18
0
class CookiesGenerator(object):
    def __init__(self, website='default'):
        """
        父类, 初始化一些对象
        :param website: 名称
        :param browser: 浏览器, 若不使用浏览器则可设置为 None
        """
        self.website = website
        self.cookies_db = RedisClient('cookies', self.website)
        self.accounts_db = RedisClient('accounts', self.website)
        self.init_browser()

    def __del__(self):
        self.close()
    
    def init_browser(self):
        """
        通过browser参数初始化全局浏览器供模拟登录使用
        :return:
        """
        if BROWSER_TYPE == 'PhantomJS':
            caps = DesiredCapabilities.PHANTOMJS
            caps[
                "phantomjs.page.settings.userAgent"] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36'
            self.browser = webdriver.PhantomJS(desired_capabilities=caps)
            self.browser.set_window_size(1400, 500)
        elif BROWSER_TYPE == 'Chrome':
            # chrome_driver = r"C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe"
            options = webdriver.ChromeOptions()
            # 此步骤很重要,设置为开发者模式,防止被各大网站识别出来使用了Selenium
            options.add_experimental_option('excludeSwitches', ['enable-automation'])
            options.add_argument('--headless')
            options.add_argument('--disable-gpu')
            options.add_argument("window-size=1024,768")
            options.add_argument("--no-sandbox")
            # driver = webdriver.Chrome(chromedriver, options=options)
            # self.browser = webdriver.Chrome(executable_path=chrome_driver, options=options)
            self.browser = webdriver.Chrome(options=options)

    def new_cookies(self, username, password):
        """
        新生成Cookies,子类需要重写
        :param username: 用户名
        :param password: 密码
        :return:
        """
        raise NotImplementedError
    
    def process_cookies(self, cookies):
        """
        处理Cookies
        :param cookies:
        :return:
        """
        dict = {}
        for cookie in cookies:
            dict[cookie['name']] = cookie['value']
        return dict
    
    def run(self):
        """
        运行, 得到所有账户, 然后顺次模拟登录
        :return:
        """
        accounts_usernames = self.accounts_db.usernames()
        cookies_usernames = self.cookies_db.usernames()
        
        for username in accounts_usernames:
            if not username in cookies_usernames:
                password = self.accounts_db.get(username)
                print('正在生成Cookies', '账号', username, '密码', password)
                result = self.new_cookies(username, password)
                # 成功获取
                if result.get('status') == 1:
                    cookies = self.process_cookies(result.get('content'))
                    print('成功获取到Cookies', cookies)
                    if self.cookies_db.set(username, json.dumps(cookies)):
                        print('成功保存Cookies')
                # 密码错误,移除账号
                elif result.get('status') == 2:
                    print(result.get('content'))
                    if self.accounts_db.delete(username):
                        print('成功删除账号')
                else:
                    print(result.get('content'))
        else:
            print('所有账号都已经成功获取Cookies')
    
    def close(self):
        """
        关闭
        :return:
        """
        try:
            print('Closing Browser')
            self.browser.close()
            del self.browser
        except TypeError:
            print('Browser not opened')
Esempio n. 19
0
class CookiesGenerator(object):
    def __init__(self, website='default'):
        """
        父类, 初始化一些对象
        :param website: 名称
        :param browser: 浏览器, 若不使用浏览器则可设置为 None
        """
        self.website = website
        self.cookies_db = RedisClient('cookies', self.website)
        self.accounts_db = RedisClient('accounts', self.website)
        self.init_browser()

    def __del__(self):
        self.close()

    def init_browser(self):
        """
        通过browser参数初始化全局浏览器供模拟登录使用
        :return:
        """
        if BROWSER_TYPE == 'PhantomJS':
            caps = DesiredCapabilities.PHANTOMJS
            caps[
                "phantomjs.page.settings.userAgent"] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36'
            self.browser = webdriver.PhantomJS(desired_capabilities=caps)
            self.browser.set_window_size(1400, 500)
        elif BROWSER_TYPE == 'Chrome':
            self.browser = webdriver.Chrome()

    def new_cookies(self, username, password):
        """
        新生成Cookies,子类需要重写
        :param username: 用户名
        :param password: 密码
        :return:
        """
        raise NotImplementedError

    def process_cookies(self, cookies):
        """
        处理Cookies
        :param cookies:
        :return:
        """
        dict = {}
        for cookie in cookies:
            dict[cookie['name']] = cookie['value']
        return dict

    def run(self):
        """
        运行, 得到所有账户, 然后顺次模拟登录
        :return:
        """
        accounts_usernames = self.accounts_db.usernames()
        cookies_usernames = self.cookies_db.usernames()

        for username in accounts_usernames:
            if not username in cookies_usernames:
                password = self.accounts_db.get(username)
                print('正在生成Cookies', '账号', username, '密码', password)
                result = self.new_cookies(username, password)
                # 成功获取
                if result.get('status') == 1:
                    cookies = self.process_cookies(result.get('content'))
                    print('成功获取到Cookies', cookies)
                    if self.cookies_db.set(username, json.dumps(cookies)):
                        print('成功保存Cookies')
                # 密码错误,移除账号
                elif result.get('status') == 2:
                    print(result.get('content'))
                    if self.accounts_db.delete(username):
                        print('成功删除账号', username)
                else:
                    print(result.get('content'))
        else:
            print('所有账号都已经成功获取Cookies')

    def close(self):
        """
        关闭
        :return:
        """
        try:
            print('Closing Browser')
            self.browser.close()
            del self.browser
        except TypeError:
            print('Browser not opened')
Esempio n. 20
0
 def __init__(self, website='default'):
     self.website = website
     self.cookies_db = RedisClient('cookies', self.website)
     self.accounts_db = RedisClient('accounts', self.website)
Esempio n. 21
0
# -*- coding: utf-8 -*-
# -*- author: GXR -*-

from cookiespool.db import RedisClient

conn = RedisClient('accounts', 'sili')


def set(account, sep='-'):
    username, password = account.split(sep)
    result = conn.set(username, password)
    print('账号', username, '密码', password)
    print('录入成功' if result else '录入失败')


def scan():
    print('请输入账号密码组(格式:账号-密码,输入exit退出读入):')
    while True:
        account = input()
        if account == 'exit':
            break
        set(account)


if __name__ == '__main__':
    scan()
Esempio n. 22
0
import requests

from cookiespool.db import RedisClient

conn = RedisClient('accounts', 'douban')


def set(account, sep='----'):
    username, password = account.split(sep)
    result = conn.set(username, password)
    print('账号', username, '密码', password)
    print('录入成功' if result else '录入失败')


def scan():
    print('请输入账号密码组, 输入exit退出读入')
    while True:
        account = input()
        if account == 'exit':
            break
        set(account)


if __name__ == '__main__':
    scan()
Esempio n. 23
0
class CookiesGenerator(object):
    #初始化一些对象
    def __init__(self, website='default'):
        self.website = website
        self.cookies_db = RedisClient('cookies', self.website)
        self.accounts_db = RedisClient('accounts', self.website)
        self.init_browser()

    #关闭Browser
    def __del__(self):
        try:
            print('Closing Browser')
            self.browser.close()
            del self.browser
        except TypeError:
            print('Browser not opened')

    #利用Browser参数初始化全局浏览器供模拟登录使用
    def init_browser(self):
        if BROWSER_TYPE == 'PhantomJS':
            caps = DesiredCapabilities.PHANTOMJS
            caps[
                'phantomjs.page.settings.userAgent']='Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36' \
                                                     ' (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36'
            self.browser = webdriver.PhantomJS(desired_capabilities=caps)
            self.browser.set_window_size(1400, 500)
        if BROWSER_TYPE == 'Chrome':
            chrome_options = webdriver.ChromeOptions()
            chrome_options.add_argument('--headless')
            self.browser = webdriver.Chrome(chrome_options=chrome_options)

    #新生成cookies,子类需要重写
    def new_cookies(self, username, password):
        raise NotImplementedError

    #处理cookies,  self.browser.get_cookies()此方法获得的cookies是个列表,其中每个元素都是个字典,我们需要取出字典中的name和value键所对应的值组成新的字典
    def process_cookies(self, cookies):
        dict = {}
        for cookie in cookies:
            dict[cookie['name']] = cookie['value']
        return dict

    #运行,得到所有账户,然后顺次模拟登陆
    def run(self):
        cookies_usernames = self.cookies_db.usernames()
        accounts_usernames = self.accounts_db.usernames()
        for username in accounts_usernames:
            if not username in cookies_usernames:
                password = self.accounts_db.get(username)
                print('正在生成Cookies', '账号', username, '密码', password)
                result = self.new_cookies(username, password)
                #成功获取
                if result.get('status') == 1:
                    cookies = self.process_cookies(result.get('content'))
                    print('成功获取到Cookies', cookies)
                    if self.cookies_db.set(username, json.dumps(cookies)):
                        print('成功保存Cookies')
                #密码错误,移除账号
                elif result.get('status') == 2:
                    print(result.get('content'))
                    if self.accounts_db.delete(username):
                        print('成功删除账号')
                else:
                    print(result.get('content'))
            else:
                print('所有账号都已成功获取Cookies')
Esempio n. 24
0
 def __init__(self):
     self.redis = RedisClient()
Esempio n. 25
0
class CookiesGenerator(object):
    def __init__(self, website='default'):
        """
        父类, 初始化一些对象
        :param website: 名称
        :param browser: 浏览器, 若不使用浏览器则可设置为 None
        """
        self.website = website
        self.cookies_db = RedisClient('cookies', self.website)
        self.accounts_db = RedisClient('accounts', self.website)
        self.init_browser()

    def __del__(self):
        self.close()

    def init_browser(self):
        """
        通过browser参数初始化全局浏览器供模拟登录使用
        :return:
        """
        self.browser = webdriver.Chrome()

    def new_cookies(self, username, password):
        """
        新生成Cookies,子类需要重写
        :param username: 用户名
        :param password: 密码
        :return:
        """
        raise NotImplementedError

    def process_cookies(self, cookies):
        """
        处理Cookies
        :param cookies:
        :return:
        """
        dict = {}
        for cookie in cookies:
            dict[cookie['name']] = cookie['value']
        return dict

    def run(self):
        """
        运行, 得到所有账户, 然后顺次模拟登录
        :return:
        """
        accounts_usernames = self.accounts_db.usernames()
        cookies_usernames = self.cookies_db.usernames()

        for username in accounts_usernames:
            if not username in cookies_usernames:
                password = self.accounts_db.get(username)
                print('正在生成Cookies', '账号', username, '密码', password)
                result = self.new_cookies(username, password)
                # 成功获取
                if result.get('status') == 1:
                    cookies = self.process_cookies(result.get('content'))
                    print('成功获取到Cookies', cookies)
                    if self.cookies_db.set(username, json.dumps(cookies)):
                        print('成功保存Cookies')
                # 密码错误,移除账号
                elif result.get('status') == 2:
                    print(result.get('content'))
                    if self.accounts_db.delete(username):
                        print('成功删除账号')
                else:
                    print(result.get('content'))
        else:
            print('所有账号都已经成功获取Cookies')

    def close(self):
        """
        关闭
        :return:
        """
        try:
            print('Closing Browser')
            self.browser.close()
            del self.browser
        except TypeError:
            print('Browser not opened')
Esempio n. 26
0
import requests

from cookiespool.db import RedisClient

conn = RedisClient('accounts', 'weibo')
pdsuconn = RedisClient('accounts', 'pdsu')


def set(account, sep='----'):
    username, password = account.split(sep)
    result = pdsuconn.set(username, password)
    print('账号', username, '密码', password)
    print('录入成功' if result else '录入失败')


def scan():
    print('请输入账号密码组, 输入exit退出读入')
    while True:
        account = input()
        if account == 'exit':
            break
        set(account)


if __name__ == '__main__':
    scan()
Esempio n. 27
0
import requests

from cookiespool.db import RedisClient

conn = RedisClient('accounts', 'zhongdeng')


def set(account, sep=' '):
    username, password = account.split(sep)
    result = conn.set(username, password)
    print('账号', username, '密码', password)
    print('录入成功' if result else '录入失败')


def scan():
    print('请输入账号密码组, 输入exit退出读入')
    while True:
        account = input()
        if account == 'exit':
            break
        set(account)


if __name__ == '__main__':
    scan()
Esempio n. 28
0
 def __init__(self):
     self.conn = RedisClient('accounts', 'xueqiu')
Esempio n. 29
0
import requests
# 修改第二次修改
from cookiespool.db import RedisClient

conn = RedisClient('accounts', 'weibo')


def set(account, sep='----'):
    username, password = account.split(sep)
    result = conn.set(username, password)
    print('账号', username, '密码', password)
    print('录入成功' if result else '录入失败')


def scan():
    print('请输入账号密码组, 输入exit退出读入')
    while True:
        account = input()
        if account == 'exit':
            break
        set(account)


if __name__ == '__main__':
    scan()
Esempio n. 30
0
import requests

from cookiespool.db import RedisClient

# conn = RedisClient('accounts', 'weibo')
conn = RedisClient('accounts', 'dbzdb')

def set(account, sep='----'):
    username, password = account.split(sep)
    result = conn.set(username, password)
    print('账号', username, '密码', password)
    print('录入成功' if result else '录入失败')


def scan():
    print('请输入账号密码组, 输入exit退出读入')
    while True:
        account = input()
        if account == 'exit':
            break
        set(account)


if __name__ == '__main__':
    scan()