Skip to content

Commit

Permalink
feat: 快手二维码登录
Browse files Browse the repository at this point in the history
  • Loading branch information
NanmiCoder committed Dec 2, 2023
1 parent 986179b commit 5c920da
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 6 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
## 功能列表
| 平台 | Cookie 登录 | 二维码登录 | 手机号登录 | 关键词搜索 | 指定视频/帖子 ID 爬取 | 登录状态缓存 | 数据保存 | IP 代理池 | 滑块验证码 |
|:---:|:---------:|:-----:|:-----:|:-----:|:-------------:|:------:|:----:|:------:|:-----:|
| 小红书 || ||||||||
| 抖音 || ||||||||
| 快手 || ||||||||
| B 站 || ||||||||
| 微博 || ||||||||
| 小红书 || ||||||||
| 抖音 || ||||||||
| 快手 || ||||||||
| B 站 || ||||||||
| 微博 || ||||||||


## 使用方法
Expand Down
49 changes: 48 additions & 1 deletion media_platform/kuaishou/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,55 @@ async def begin(self):
else:
raise ValueError("Invalid Login Type Currently only supported qrcode or phone or cookie ...")

@retry(stop=stop_after_attempt(20), wait=wait_fixed(1), retry=retry_if_result(lambda value: value is False))
async def check_login_state(self) -> bool:
"""
Check if the current login status is successful and return True otherwise return False
retry decorator will retry 20 times if the return value is False, and the retry interval is 1 second
if max retry times reached, raise RetryError
"""
current_cookie = await self.browser_context.cookies()
_, cookie_dict = utils.convert_cookies(current_cookie)
kuaishou_pass_token = cookie_dict.get("passToken")
if kuaishou_pass_token:
return True
return False

async def login_by_qrcode(self):
pass
"""login kuaishou website and keep webdriver login state"""
utils.logger.info("Begin login kuaishou by qrcode ...")

# click login button
login_button_ele = self.context_page.locator(
"xpath=//p[text()=' 登录 ']"
)
await login_button_ele.click()

# find login qrcode
qrcode_img_selector = "//div[@class='qrcode-img']//img"
base64_qrcode_img = await utils.find_login_qrcode(
self.context_page,
selector=qrcode_img_selector
)
if not base64_qrcode_img:
utils.logger.info("login failed , have not found qrcode please check ....")
sys.exit()


# show login qrcode
partial_show_qrcode = functools.partial(utils.show_qrcode, base64_qrcode_img)
asyncio.get_running_loop().run_in_executor(executor=None, func=partial_show_qrcode)

utils.logger.info(f"waiting for scan code login, remaining time is 20s")
try:
await self.check_login_state()
except RetryError:
utils.logger.info("Login kuaishou failed by qrcode login method ...")
sys.exit()

wait_redirect_seconds = 5
utils.logger.info(f"Login successful then wait for {wait_redirect_seconds} seconds redirect ...")
await asyncio.sleep(wait_redirect_seconds)

async def login_by_mobile(self):
pass
Expand Down

0 comments on commit 5c920da

Please sign in to comment.