liufuhua007

fixbug

......@@ -72,13 +72,32 @@ async def main():
elif args.platform == SOCIAL_MEDIA_KUAISHOU:
await ks_setup(str(account_file), handle=True)
elif args.platform == SOCIAL_MEDIA_WANGYIHAO:
await wyh_setup(str(account_file), handle=True)
await wyh_setup(str(account_file), handle=True, auto=False)
# elif args.platform == SOCIAL_MEDIA_XHS:
# await xhs_setup(str(account_file), handle=True)
elif args.platform == SOCIAL_MEDIA_TOUTIAO:
await toutiao_setup(str(account_file), handle=True)
await toutiao_setup(str(account_file), handle=True, auto=False)
elif args.platform == SOCIAL_MEDIA_BAIJIAHAO:
await toutiao_setup(str(account_file), handle=True)
await toutiao_setup(str(account_file), handle=True, auto=False)
elif args.action == 'auto_login':
print(f"auto Logging in with account {args.account_name} on platform {args.platform}")
if args.platform == SOCIAL_MEDIA_DOUYIN:
await douyin_setup(str(account_file), handle=True)
elif args.platform == SOCIAL_MEDIA_TIKTOK:
await tiktok_setup(str(account_file), handle=True)
elif args.platform == SOCIAL_MEDIA_TENCENT:
await weixin_setup(str(account_file), handle=True)
elif args.platform == SOCIAL_MEDIA_KUAISHOU:
await ks_setup(str(account_file), handle=True)
elif args.platform == SOCIAL_MEDIA_WANGYIHAO:
await wyh_setup(str(account_file), handle=True, auto=True)
# elif args.platform == SOCIAL_MEDIA_XHS:
# await xhs_setup(str(account_file), handle=True)
elif args.platform == SOCIAL_MEDIA_TOUTIAO:
await toutiao_setup(str(account_file), handle=True, auto=True)
elif args.platform == SOCIAL_MEDIA_BAIJIAHAO:
await toutiao_setup(str(account_file), handle=True, auto=True)
elif args.action == 'upload':
title, tags = get_title_and_hashtags(args.video_file)
......
......@@ -6,20 +6,20 @@ from utils.log import kuaishou_logger
from playwright.async_api import Playwright, async_playwright
async def wyh_setup(account_file, handle=False):
async def bjh_setup(account_file, handle=False):
print(account_file)
account_file = get_absolute_path(account_file, "wyh_uploader")
if not os.path.exists(account_file):
if not handle:
return False
kuaishou_logger.info('[+] cookie文件不存在或已失效,即将自动打开浏览器,请扫码登录,登陆后会自动生成cookie文件')
await get_wyh_cookie(account_file)
await get_bjh_cookie(account_file)
else:
await open_wyh_main_page(account_file)
await open_bjh_main_page(account_file)
return True
async def open_wyh_main_page(account_file):
async def open_bjh_main_page(account_file):
async with async_playwright() as playwright:
options = {
'args': [
......@@ -55,7 +55,7 @@ async def open_wyh_main_page(account_file):
browser.close()
async def get_wyh_cookie(account_file):
async def get_bjh_cookie(account_file):
print("get_wyh_cookie")
async with async_playwright() as playwright:
options = {
......@@ -77,6 +77,12 @@ async def get_wyh_cookie(account_file):
# await context.storage_state(path=account_file)
# 自动登陆
await page.wait_for_timeout(20000)
await page.wait_for_timeout(2000)
await page.get_by_text('注册/登录百家号').click()
await page.pause()
await page.wait_for_timeout(2000)
await page.locator("//*[@class='pass-text-input pass-text-input-userName']").fill("idiotbc")
await page.wait_for_timeout(2000)
await page.locator("//*[@class='pass-text-input pass-text-input-password']").fill("Liuyihong1023@")
await page.wait_for_timeout(2000)
await page.locator("//*[@class='pass-checkbox-input pass-checkbox-isAgree']").click()
await page.wait_for_timeout(2000)
......
......@@ -6,20 +6,23 @@ from utils.log import kuaishou_logger
from playwright.async_api import Playwright, async_playwright
async def toutiao_setup(account_file, handle=False):
async def toutiao_setup(account_file, handle=False, auto=False):
print(account_file)
account_file = get_absolute_path(account_file, "wyh_uploader")
if not os.path.exists(account_file):
if not handle:
return False
kuaishou_logger.info('[+] cookie文件不存在或已失效,即将自动打开浏览器,请扫码登录,登陆后会自动生成cookie文件')
await get_wyh_cookie(account_file)
if not auto:
await get_toutiao_cookie(account_file)
else:
await open_wyh_main_page(account_file)
await get_toutiao_cookie_auto(account_file)
else:
await open_toutiao_main_page(account_file)
return True
async def open_wyh_main_page(account_file):
async def open_toutiao_main_page(account_file):
async with async_playwright() as playwright:
options = {
'args': [
......@@ -39,8 +42,8 @@ async def open_wyh_main_page(account_file):
browser.close()
async def get_wyh_cookie(account_file):
print("get_wyh_cookie")
async def get_toutiao_cookie_auto(account_file):
print("get_toutiao_cookie")
async with async_playwright() as playwright:
options = {
'args': [
......@@ -57,24 +60,44 @@ async def get_wyh_cookie(account_file):
page = await context.new_page()
await page.goto("https://mp.toutiao.com")
# 手动授权登录
# await page.pause()
# 点击调试器的继续,保存cookie
# await context.storage_state(path=account_file)
# 自动登陆
await page.wait_for_timeout(5000)
await page.wait_for_timeout(2000)
await page.get_by_text('密码登录').click()
await page.wait_for_timeout(5000)
await page.wait_for_timeout(2000)
await page.get_by_placeholder("手机号/邮箱").fill('18610534668')
print("输入账号成功")
await page.wait_for_timeout(1000)
await page.get_by_placeholder('密码').fill("Liuyihong1023@")
await page.wait_for_timeout(1000)
await page.wait_for_timeout(2000)
await page.locator("//*[@class='web-login-confirm-info__checkbox']").click()
await page.wait_for_timeout(1000)
await page.wait_for_timeout(2000)
await page.locator("//*[@class='web-login-button']").click()
await page.wait_for_timeout(10000)
await page.wait_for_timeout(2000)
# 点击调试器的继续,保存cookie
await context.storage_state(path=account_file)
async def get_toutiao_cookie(account_file):
print("get_toutiao_cookie")
async with async_playwright() as playwright:
options = {
'args': [
'--lang en-GB'
],
'headless': False, # Set headless option here
}
# Make sure to run headed.
browser = await playwright.chromium.launch(**options)
# Setup context however you like.
context = await browser.new_context() # Pass any options
context = await set_init_script(context)
# Pause the page, and start recording manually.
page = await context.new_page()
await page.goto("https://mp.toutiao.com")
# 手动授权登录
await page.pause()
# 点击调试器的继续,保存cookie
await context.storage_state(path=account_file)
......
......@@ -6,20 +6,26 @@ from utils.log import kuaishou_logger
from playwright.async_api import Playwright, async_playwright
async def wyh_setup(account_file, handle=False):
async def wyh_setup(account_file, handle=False, auto=False):
print(account_file)
account_file = get_absolute_path(account_file, "wyh_uploader")
if not os.path.exists(account_file):
if not handle:
return False
kuaishou_logger.info('[+] cookie文件不存在或已失效,即将自动打开浏览器,请扫码登录,登陆后会自动生成cookie文件')
if not auto:
await get_wyh_cookie(account_file)
else:
await get_wyh_cookie_auto(account_file)
else:
await open_wyh_main_page(account_file)
return True
async def open_wyh_main_page(account_file):
'''
'''
async def get_wyh_cookie_auto(account_file):
print("get_wyh_cookie")
async with async_playwright() as playwright:
options = {
'args': [
......@@ -30,33 +36,29 @@ async def open_wyh_main_page(account_file):
# Make sure to run headed.
browser = await playwright.chromium.launch(**options)
# Setup context however you like.
context = await browser.new_context(storage_state=account_file) # Pass any options
context = await browser.new_context() # Pass any options
context = await set_init_script(context)
# Pause the page, and start recording manually.
page = await context.new_page()
await page.goto("https://mp.163.com")
# await page.pause()
# 点击调试器的继续,保存cookie
# await context.storage_state(path=account_file)
board = page.locator("//*[@class='homeV4__board__card__data__value']")
# html_content = await board.inner_html()
# print(html_content)
content = await board.nth(0).inner_text() #总粉丝数
print(content)
content = await board.nth(1).inner_text() #总阅读数
print(content)
content = await board.nth(2).inner_text() #总收益
print(content)
await page.get_by_text("粉丝数据").click()
await page.wait_for_timeout(5000)
await page.get_by_text("内容数据").click()
# 自动登陆
await page.wait_for_timeout(5000)
await page.get_by_text("收益数据").click()
frame = page.frame_locator('//iframe[contains(@id, "x-URS-iframe")]')
await frame.locator('[name="email"]').fill('liufuhua007@163.com')
await frame.locator('[name="password"]').fill("Liuyihong1023@")
await frame.locator('#dologin').click()
# await page.pause()
await page.wait_for_timeout(5000)
browser.close()
# 点击调试器的继续,保存cookie
await context.storage_state(path=account_file)
async def get_wyh_cookie(account_file):
print("get_wyh_cookie")
async with async_playwright() as playwright:
options = {
'args': [
......@@ -67,23 +69,47 @@ async def get_wyh_cookie(account_file):
# Make sure to run headed.
browser = await playwright.chromium.launch(**options)
# Setup context however you like.
context = await browser.new_context() # Pass any options
context = await browser.new_context(storage_state=account_file) # Pass any options
context = await set_init_script(context)
# Pause the page, and start recording manually.
page = await context.new_page()
await page.goto("https://mp.163.com")
# await page.pause()
# 点击调试器的继续,保存cookie
# await context.storage_state(path=account_file)
await page.pause()
async def open_wyh_main_page(account_file):
async with async_playwright() as playwright:
options = {
'args': [
'--lang en-GB'
],
'headless': False, # Set headless option here
}
# Make sure to run headed.
browser = await playwright.chromium.launch(**options)
# Setup context however you like.
context = await browser.new_context(storage_state=account_file) # Pass any options
context = await set_init_script(context)
# Pause the page, and start recording manually.
page = await context.new_page()
await page.goto("https://mp.163.com")
board = page.locator("//*[@class='homeV4__board__card__data__value']")
# html_content = await board.inner_html()
# print(html_content)
content = await board.nth(0).inner_text() #总粉丝数
print(content)
content = await board.nth(1).inner_text() #总阅读数
print(content)
content = await board.nth(2).inner_text() #总收益
print(content)
await page.get_by_text("粉丝数据").click()
await page.wait_for_timeout(5000)
await page.get_by_text("内容数据").click()
await page.wait_for_timeout(5000)
await page.get_by_text("收益数据").click()
await page.wait_for_timeout(5000)
browser.close()
# 自动登陆
await page.wait_for_timeout(20000)
frame = page.frame_locator('//iframe[contains(@id, "x-URS-iframe")]')
await frame.locator('[name="email"]').fill('liufuhua007@163.com')
await frame.locator('[name="password"]').fill("Liuyihong1023@")
await frame.locator('#dologin').click()
# await page.pause()
await page.wait_for_timeout(15000)
# 点击调试器的继续,保存cookie
await context.storage_state(path=account_file)
......
......@@ -20,7 +20,7 @@ def get_supported_social_media() -> List[str]:
def get_cli_action() -> List[str]:
return ["upload", "login", "watch"]
return ["upload", "login", "watch", "auto_login"]
async def set_init_script(context):
......