Browse Source

v1.1

pull/4/head
OSinoooO 6 years ago
parent
commit
0a7a8c7ce2
  1. 8
      cookiespool/config.py
  2. 5
      cookiespool/generator.py
  3. 2
      cookiespool/importer.py
  4. 6
      login/weibo/cookies.py

8
cookiespool/config.py

@ -5,7 +5,7 @@ REDIS_HOST = 'localhost'
REDIS_PORT = 6379
# Redis密码,如无填None
REDIS_PASSWORD = 'foobared'
REDIS_PASSWORD = None
# 产生器使用的浏览器
BROWSER_TYPE = 'Chrome'
@ -28,12 +28,12 @@ TEST_URL_MAP = {
CYCLE = 120
# API地址和端口
API_HOST = '0.0.0.0'
API_HOST = '127.0.0.1'
API_PORT = 5000
# 产生器开关,模拟登录添加Cookies
GENERATOR_PROCESS = False
GENERATOR_PROCESS = True
# 验证器开关,循环检测数据库中Cookies是否可用,不可用删除
VALID_PROCESS = False
VALID_PROCESS = True
# API接口服务
API_PROCESS = True

5
cookiespool/generator.py

@ -1,6 +1,7 @@
import json
from selenium import webdriver
from selenium.webdriver import DesiredCapabilities
from selenium.webdriver.chrome.options import Options
from cookiespool.config import *
from cookiespool.db import RedisClient
from login.weibo.cookies import WeiboCookies
@ -33,7 +34,9 @@ class CookiesGenerator(object):
self.browser = webdriver.PhantomJS(desired_capabilities=caps)
self.browser.set_window_size(1400, 500)
elif BROWSER_TYPE == 'Chrome':
self.browser = webdriver.Chrome()
chrome_options = Options()
chrome_options.add_argument('--headless')
self.browser = webdriver.Chrome(chrome_options=chrome_options)
def new_cookies(self, username, password):
"""

2
cookiespool/importer.py

@ -5,7 +5,7 @@ from cookiespool.db import RedisClient
conn = RedisClient('accounts', 'weibo')
def set(account, sep='----'):
username, password = account.split(sep)
username, password = account.split(' ')
result = conn.set(username, password)
print('账号', username, '密码', password)
print('录入成功' if result else '录入失败')

6
login/weibo/cookies.py

@ -53,7 +53,7 @@ class WeiboCookies():
"""
try:
return bool(
WebDriverWait(self.browser, 5).until(EC.presence_of_element_located((By.CLASS_NAME, 'drop-title'))))
WebDriverWait(self.browser, 5).until(EC.presence_of_element_located((By.CLASS_NAME, 'main-wrap'))))
except TimeoutException:
return False
@ -67,6 +67,7 @@ class WeiboCookies():
except TimeoutException:
print('未出现验证码')
self.open()
return ''
time.sleep(2)
location = img.location
size = img.size
@ -210,6 +211,7 @@ class WeiboCookies():
'status': 1,
'content': cookies
}
else:
# 获取验证码图片
image = self.get_image('captcha.png')
numbers = self.detect_image(image)
@ -228,5 +230,5 @@ class WeiboCookies():
if __name__ == '__main__':
result = WeiboCookies('14773427930', 'x6pybpakq1').main()
result = WeiboCookies('14773427930', 'x6pybpakq1', 'Chrome').main()
print(result)

Loading…
Cancel
Save