def __init__(self): self.account_db = RedisClient('jdaccount') self.cookies_db = RedisClient('jdcookies') self.headers = { 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 ' } self.testUrl = 'https://www.jd.com/'
def __init__(self, website='default'): self.website = website self.cookies_db = RedisClient('cookies', self.website) self.accounts_db = RedisClient('accounts', self.website) self.header = { 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 ' }
def __init__(self,url,yanse): self.url = url # yanse为为我们下单上面的颜色类目选项 self.yanse = yanse self.brower = webdriver.Chrome() self.wait = WebDriverWait(self.brower,30) self.cookies_db = RedisClient('jdcookies')
def __init__(self): self.redis = RedisClient()
def __init__(self): self.redis = RedisClient() self.crawler = Crawler()
# 此文件用来添加我们自己的账号到redis中 # 创建cookie池肯定会用到大量的账号,所以我们这边以txt文件为例,不用我们手动输入了 # 将事先申请好的账号密码保存到txt文件中,格式为:账号---密码,然后直接读取就行 # 默认放到同路径下的account.txt中, from save import RedisClient # 先实例化Readis类,参入key名字 conn = RedisClient('account', 'cf') def readaccount(sp='----'): print('开始读取读取account.txt文件......') with open("account.txt", "r") as f: datas = f.readlines() # readlinses方法是将txt文件中的内容以列表形式输出 for data in datas: # 由于txt文件中自带\n,所以我们先去除换行符然后分割账号密码 account, password = data.strip('\n').split(sp) print("正在导入账号:%s 密码:%s" % (account, password)) # 调用我们实现写好的set方法将账号密码储存到redis中 result = conn.set(account, password) print('导入成功\n' if result else '导入失败') if __name__ == "__main__": readaccount()
def __init__(self, name='jdcookies'): self.name = name self.account_db = RedisClient('jdaccount') self.cookies_db = RedisClient(self.name)
''' 此文件为账号导入模块,将我们提前写好的账号全部导入到redis中 我们单独建立一个account.txt来集中存放账号密码,来提高效率 date:2021.3.2 author:焦康阳 blog:https://jiaokangyang.com ''' from save import RedisClient jd = RedisClient('jdaccount') # 我们txt文件中用----将账号密码隔开, def readaccount(sp='----'): print('开始导入账号密码,正在读取account.txt') with open('account.txt', 'r') as f: datas = f.readlines() for data in datas: username, password = data.strip('\n').split(sp) print('正在导入账号:%s 密码:%s' % (username, password)) result = jd.set(username, password) print('导入成功' if result else '导入失败')
def __init__(self, website='default'): self.website = website self.cookies_db = RedisClient('cookies', self.website) self.account_db = RedisClient('account', self.website) self.init_browser()
def get_conn(): if not hasattr(g,'redis'): g.redis=RedisClient() return g.redis