Пример #1
0
 def __init__(self, website="default"):
     """
     父类, 初始化一些对象
     :param website:
     """
     self.website = website
     self.cookies_db = RedisClient("cookies", self.website)
     self.accounts_db = RedisClient("accounts", self.website)
     self.init_browser()
Пример #2
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)
Пример #3
0
class ValidTester():
    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)
Пример #4
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)
        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)
        if 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 username not 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)
                    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')
Пример #5
0
 def __init__(self, website='default'):
     self.website = website
     self.cookies_db = RedisClient('cookies', self.website)
     self.accounts_db = RedisClient('accounts', self.website)
Пример #6
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()
Пример #7
0
# -*- coding: utf-8 -*-
# @Time    : 2019/3/18 10:23
# @Author  : yueconger
# @File    : importer.py
import requests

from CookiesPool.db import RedisClient

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


def set(account, sep='----'):
    """账号信息格式提前设置为 username----password"""
    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()
Пример #8
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 __del__(self):
        self.close()

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

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

    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)
                print('result', result)
                # 成功获取
                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')
        except TypeError:
            print('Browser not opened')
Пример #9
0
# -*- coding: utf-8 -*-
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 print('录入失败'))


def scan():
    print("请输入账号密码,以':'分隔,输入exit退出读入")
    while True:
        accpunt = input()
        if accpunt == 'exit':
            break
        set(accpunt)


if __name__ == '__main__':
    scan()
Пример #10
0
class CookiesGenerator(object):
    def __init__(self, website='default'):
        """
        父类, 初始化一些对象
        :param website: 名称
        :param browser: 浏览器, 若不使用浏览器则可设置为 None
        """
        self.website = website
        self.cookie_db = RedisClient('cookies', self.website)
        self.accounts_db = RedisClient('accounts', self.website)

    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):
        """
        处理cookie
        :param cookies:
        :return:
        """
        dicts = {}
        for cookie in cookies:
            dicts[cookie['name']] = cookie['value']
        return dicts

    def run(self):
        """
        运行, 得到所有账户, 然后顺次模拟登录
        :return:
        """
        accounts_usernames = self.accounts_db.usernames()
        cookies_usernames = self.cookie_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')