Showing
5 changed files
with
134 additions
and
60 deletions
| ... | @@ -72,13 +72,32 @@ async def main(): | ... | @@ -72,13 +72,32 @@ async def main(): |
| 72 | elif args.platform == SOCIAL_MEDIA_KUAISHOU: | 72 | elif args.platform == SOCIAL_MEDIA_KUAISHOU: |
| 73 | await ks_setup(str(account_file), handle=True) | 73 | await ks_setup(str(account_file), handle=True) |
| 74 | elif args.platform == SOCIAL_MEDIA_WANGYIHAO: | 74 | elif args.platform == SOCIAL_MEDIA_WANGYIHAO: |
| 75 | - await wyh_setup(str(account_file), handle=True) | 75 | + await wyh_setup(str(account_file), handle=True, auto=False) |
| 76 | # elif args.platform == SOCIAL_MEDIA_XHS: | 76 | # elif args.platform == SOCIAL_MEDIA_XHS: |
| 77 | # await xhs_setup(str(account_file), handle=True) | 77 | # await xhs_setup(str(account_file), handle=True) |
| 78 | elif args.platform == SOCIAL_MEDIA_TOUTIAO: | 78 | elif args.platform == SOCIAL_MEDIA_TOUTIAO: |
| 79 | - await toutiao_setup(str(account_file), handle=True) | 79 | + await toutiao_setup(str(account_file), handle=True, auto=False) |
| 80 | elif args.platform == SOCIAL_MEDIA_BAIJIAHAO: | 80 | elif args.platform == SOCIAL_MEDIA_BAIJIAHAO: |
| 81 | - await toutiao_setup(str(account_file), handle=True) | 81 | + await toutiao_setup(str(account_file), handle=True, auto=False) |
| 82 | + | ||
| 83 | + elif args.action == 'auto_login': | ||
| 84 | + print(f"auto Logging in with account {args.account_name} on platform {args.platform}") | ||
| 85 | + if args.platform == SOCIAL_MEDIA_DOUYIN: | ||
| 86 | + await douyin_setup(str(account_file), handle=True) | ||
| 87 | + elif args.platform == SOCIAL_MEDIA_TIKTOK: | ||
| 88 | + await tiktok_setup(str(account_file), handle=True) | ||
| 89 | + elif args.platform == SOCIAL_MEDIA_TENCENT: | ||
| 90 | + await weixin_setup(str(account_file), handle=True) | ||
| 91 | + elif args.platform == SOCIAL_MEDIA_KUAISHOU: | ||
| 92 | + await ks_setup(str(account_file), handle=True) | ||
| 93 | + elif args.platform == SOCIAL_MEDIA_WANGYIHAO: | ||
| 94 | + await wyh_setup(str(account_file), handle=True, auto=True) | ||
| 95 | + # elif args.platform == SOCIAL_MEDIA_XHS: | ||
| 96 | + # await xhs_setup(str(account_file), handle=True) | ||
| 97 | + elif args.platform == SOCIAL_MEDIA_TOUTIAO: | ||
| 98 | + await toutiao_setup(str(account_file), handle=True, auto=True) | ||
| 99 | + elif args.platform == SOCIAL_MEDIA_BAIJIAHAO: | ||
| 100 | + await toutiao_setup(str(account_file), handle=True, auto=True) | ||
| 82 | 101 | ||
| 83 | elif args.action == 'upload': | 102 | elif args.action == 'upload': |
| 84 | title, tags = get_title_and_hashtags(args.video_file) | 103 | title, tags = get_title_and_hashtags(args.video_file) | ... | ... |
| ... | @@ -6,20 +6,20 @@ from utils.log import kuaishou_logger | ... | @@ -6,20 +6,20 @@ from utils.log import kuaishou_logger |
| 6 | from playwright.async_api import Playwright, async_playwright | 6 | from playwright.async_api import Playwright, async_playwright |
| 7 | 7 | ||
| 8 | 8 | ||
| 9 | -async def wyh_setup(account_file, handle=False): | 9 | +async def bjh_setup(account_file, handle=False): |
| 10 | print(account_file) | 10 | print(account_file) |
| 11 | account_file = get_absolute_path(account_file, "wyh_uploader") | 11 | account_file = get_absolute_path(account_file, "wyh_uploader") |
| 12 | if not os.path.exists(account_file): | 12 | if not os.path.exists(account_file): |
| 13 | if not handle: | 13 | if not handle: |
| 14 | return False | 14 | return False |
| 15 | kuaishou_logger.info('[+] cookie文件不存在或已失效,即将自动打开浏览器,请扫码登录,登陆后会自动生成cookie文件') | 15 | kuaishou_logger.info('[+] cookie文件不存在或已失效,即将自动打开浏览器,请扫码登录,登陆后会自动生成cookie文件') |
| 16 | - await get_wyh_cookie(account_file) | 16 | + await get_bjh_cookie(account_file) |
| 17 | else: | 17 | else: |
| 18 | - await open_wyh_main_page(account_file) | 18 | + await open_bjh_main_page(account_file) |
| 19 | return True | 19 | return True |
| 20 | 20 | ||
| 21 | 21 | ||
| 22 | -async def open_wyh_main_page(account_file): | 22 | +async def open_bjh_main_page(account_file): |
| 23 | async with async_playwright() as playwright: | 23 | async with async_playwright() as playwright: |
| 24 | options = { | 24 | options = { |
| 25 | 'args': [ | 25 | 'args': [ |
| ... | @@ -55,7 +55,7 @@ async def open_wyh_main_page(account_file): | ... | @@ -55,7 +55,7 @@ async def open_wyh_main_page(account_file): |
| 55 | browser.close() | 55 | browser.close() |
| 56 | 56 | ||
| 57 | 57 | ||
| 58 | -async def get_wyh_cookie(account_file): | 58 | +async def get_bjh_cookie(account_file): |
| 59 | print("get_wyh_cookie") | 59 | print("get_wyh_cookie") |
| 60 | async with async_playwright() as playwright: | 60 | async with async_playwright() as playwright: |
| 61 | options = { | 61 | options = { |
| ... | @@ -77,6 +77,12 @@ async def get_wyh_cookie(account_file): | ... | @@ -77,6 +77,12 @@ async def get_wyh_cookie(account_file): |
| 77 | # await context.storage_state(path=account_file) | 77 | # await context.storage_state(path=account_file) |
| 78 | 78 | ||
| 79 | # 自动登陆 | 79 | # 自动登陆 |
| 80 | - await page.wait_for_timeout(20000) | 80 | + await page.wait_for_timeout(2000) |
| 81 | await page.get_by_text('注册/登录百家号').click() | 81 | await page.get_by_text('注册/登录百家号').click() |
| 82 | - await page.pause() | 82 | + await page.wait_for_timeout(2000) |
| 83 | + await page.locator("//*[@class='pass-text-input pass-text-input-userName']").fill("idiotbc") | ||
| 84 | + await page.wait_for_timeout(2000) | ||
| 85 | + await page.locator("//*[@class='pass-text-input pass-text-input-password']").fill("Liuyihong1023@") | ||
| 86 | + await page.wait_for_timeout(2000) | ||
| 87 | + await page.locator("//*[@class='pass-checkbox-input pass-checkbox-isAgree']").click() | ||
| 88 | + await page.wait_for_timeout(2000) | ... | ... |
| ... | @@ -6,20 +6,23 @@ from utils.log import kuaishou_logger | ... | @@ -6,20 +6,23 @@ from utils.log import kuaishou_logger |
| 6 | from playwright.async_api import Playwright, async_playwright | 6 | from playwright.async_api import Playwright, async_playwright |
| 7 | 7 | ||
| 8 | 8 | ||
| 9 | -async def toutiao_setup(account_file, handle=False): | 9 | +async def toutiao_setup(account_file, handle=False, auto=False): |
| 10 | print(account_file) | 10 | print(account_file) |
| 11 | account_file = get_absolute_path(account_file, "wyh_uploader") | 11 | account_file = get_absolute_path(account_file, "wyh_uploader") |
| 12 | if not os.path.exists(account_file): | 12 | if not os.path.exists(account_file): |
| 13 | if not handle: | 13 | if not handle: |
| 14 | return False | 14 | return False |
| 15 | kuaishou_logger.info('[+] cookie文件不存在或已失效,即将自动打开浏览器,请扫码登录,登陆后会自动生成cookie文件') | 15 | kuaishou_logger.info('[+] cookie文件不存在或已失效,即将自动打开浏览器,请扫码登录,登陆后会自动生成cookie文件') |
| 16 | - await get_wyh_cookie(account_file) | 16 | + if not auto: |
| 17 | + await get_toutiao_cookie(account_file) | ||
| 17 | else: | 18 | else: |
| 18 | - await open_wyh_main_page(account_file) | 19 | + await get_toutiao_cookie_auto(account_file) |
| 20 | + else: | ||
| 21 | + await open_toutiao_main_page(account_file) | ||
| 19 | return True | 22 | return True |
| 20 | 23 | ||
| 21 | 24 | ||
| 22 | -async def open_wyh_main_page(account_file): | 25 | +async def open_toutiao_main_page(account_file): |
| 23 | async with async_playwright() as playwright: | 26 | async with async_playwright() as playwright: |
| 24 | options = { | 27 | options = { |
| 25 | 'args': [ | 28 | 'args': [ |
| ... | @@ -39,8 +42,8 @@ async def open_wyh_main_page(account_file): | ... | @@ -39,8 +42,8 @@ async def open_wyh_main_page(account_file): |
| 39 | browser.close() | 42 | browser.close() |
| 40 | 43 | ||
| 41 | 44 | ||
| 42 | -async def get_wyh_cookie(account_file): | 45 | +async def get_toutiao_cookie_auto(account_file): |
| 43 | - print("get_wyh_cookie") | 46 | + print("get_toutiao_cookie") |
| 44 | async with async_playwright() as playwright: | 47 | async with async_playwright() as playwright: |
| 45 | options = { | 48 | options = { |
| 46 | 'args': [ | 49 | 'args': [ |
| ... | @@ -57,24 +60,44 @@ async def get_wyh_cookie(account_file): | ... | @@ -57,24 +60,44 @@ async def get_wyh_cookie(account_file): |
| 57 | page = await context.new_page() | 60 | page = await context.new_page() |
| 58 | await page.goto("https://mp.toutiao.com") | 61 | await page.goto("https://mp.toutiao.com") |
| 59 | 62 | ||
| 60 | - # 手动授权登录 | ||
| 61 | - # await page.pause() | ||
| 62 | - # 点击调试器的继续,保存cookie | ||
| 63 | - # await context.storage_state(path=account_file) | ||
| 64 | - | ||
| 65 | # 自动登陆 | 63 | # 自动登陆 |
| 66 | - await page.wait_for_timeout(5000) | 64 | + await page.wait_for_timeout(2000) |
| 67 | await page.get_by_text('密码登录').click() | 65 | await page.get_by_text('密码登录').click() |
| 68 | - await page.wait_for_timeout(5000) | 66 | + await page.wait_for_timeout(2000) |
| 69 | 67 | ||
| 70 | await page.get_by_placeholder("手机号/邮箱").fill('18610534668') | 68 | await page.get_by_placeholder("手机号/邮箱").fill('18610534668') |
| 71 | print("输入账号成功") | 69 | print("输入账号成功") |
| 72 | await page.wait_for_timeout(1000) | 70 | await page.wait_for_timeout(1000) |
| 73 | await page.get_by_placeholder('密码').fill("Liuyihong1023@") | 71 | await page.get_by_placeholder('密码').fill("Liuyihong1023@") |
| 74 | - await page.wait_for_timeout(1000) | 72 | + await page.wait_for_timeout(2000) |
| 75 | await page.locator("//*[@class='web-login-confirm-info__checkbox']").click() | 73 | await page.locator("//*[@class='web-login-confirm-info__checkbox']").click() |
| 76 | - await page.wait_for_timeout(1000) | 74 | + await page.wait_for_timeout(2000) |
| 77 | await page.locator("//*[@class='web-login-button']").click() | 75 | await page.locator("//*[@class='web-login-button']").click() |
| 78 | - await page.wait_for_timeout(10000) | 76 | + await page.wait_for_timeout(2000) |
| 79 | # 点击调试器的继续,保存cookie | 77 | # 点击调试器的继续,保存cookie |
| 80 | await context.storage_state(path=account_file) | 78 | await context.storage_state(path=account_file) |
| 79 | + | ||
| 80 | + | ||
| 81 | +async def get_toutiao_cookie(account_file): | ||
| 82 | + print("get_toutiao_cookie") | ||
| 83 | + async with async_playwright() as playwright: | ||
| 84 | + options = { | ||
| 85 | + 'args': [ | ||
| 86 | + '--lang en-GB' | ||
| 87 | + ], | ||
| 88 | + 'headless': False, # Set headless option here | ||
| 89 | + } | ||
| 90 | + # Make sure to run headed. | ||
| 91 | + browser = await playwright.chromium.launch(**options) | ||
| 92 | + # Setup context however you like. | ||
| 93 | + context = await browser.new_context() # Pass any options | ||
| 94 | + context = await set_init_script(context) | ||
| 95 | + # Pause the page, and start recording manually. | ||
| 96 | + page = await context.new_page() | ||
| 97 | + await page.goto("https://mp.toutiao.com") | ||
| 98 | + | ||
| 99 | + # 手动授权登录 | ||
| 100 | + await page.pause() | ||
| 101 | + # 点击调试器的继续,保存cookie | ||
| 102 | + await context.storage_state(path=account_file) | ||
| 103 | + | ... | ... |
| ... | @@ -6,20 +6,26 @@ from utils.log import kuaishou_logger | ... | @@ -6,20 +6,26 @@ from utils.log import kuaishou_logger |
| 6 | from playwright.async_api import Playwright, async_playwright | 6 | from playwright.async_api import Playwright, async_playwright |
| 7 | 7 | ||
| 8 | 8 | ||
| 9 | -async def wyh_setup(account_file, handle=False): | 9 | +async def wyh_setup(account_file, handle=False, auto=False): |
| 10 | print(account_file) | 10 | print(account_file) |
| 11 | account_file = get_absolute_path(account_file, "wyh_uploader") | 11 | account_file = get_absolute_path(account_file, "wyh_uploader") |
| 12 | if not os.path.exists(account_file): | 12 | if not os.path.exists(account_file): |
| 13 | if not handle: | 13 | if not handle: |
| 14 | return False | 14 | return False |
| 15 | kuaishou_logger.info('[+] cookie文件不存在或已失效,即将自动打开浏览器,请扫码登录,登陆后会自动生成cookie文件') | 15 | kuaishou_logger.info('[+] cookie文件不存在或已失效,即将自动打开浏览器,请扫码登录,登陆后会自动生成cookie文件') |
| 16 | + if not auto: | ||
| 16 | await get_wyh_cookie(account_file) | 17 | await get_wyh_cookie(account_file) |
| 17 | else: | 18 | else: |
| 19 | + await get_wyh_cookie_auto(account_file) | ||
| 20 | + else: | ||
| 18 | await open_wyh_main_page(account_file) | 21 | await open_wyh_main_page(account_file) |
| 19 | return True | 22 | return True |
| 20 | 23 | ||
| 21 | 24 | ||
| 22 | -async def open_wyh_main_page(account_file): | 25 | +''' |
| 26 | +''' | ||
| 27 | +async def get_wyh_cookie_auto(account_file): | ||
| 28 | + print("get_wyh_cookie") | ||
| 23 | async with async_playwright() as playwright: | 29 | async with async_playwright() as playwright: |
| 24 | options = { | 30 | options = { |
| 25 | 'args': [ | 31 | 'args': [ |
| ... | @@ -30,33 +36,29 @@ async def open_wyh_main_page(account_file): | ... | @@ -30,33 +36,29 @@ async def open_wyh_main_page(account_file): |
| 30 | # Make sure to run headed. | 36 | # Make sure to run headed. |
| 31 | browser = await playwright.chromium.launch(**options) | 37 | browser = await playwright.chromium.launch(**options) |
| 32 | # Setup context however you like. | 38 | # Setup context however you like. |
| 33 | - context = await browser.new_context(storage_state=account_file) # Pass any options | 39 | + context = await browser.new_context() # Pass any options |
| 34 | context = await set_init_script(context) | 40 | context = await set_init_script(context) |
| 35 | # Pause the page, and start recording manually. | 41 | # Pause the page, and start recording manually. |
| 36 | page = await context.new_page() | 42 | page = await context.new_page() |
| 37 | await page.goto("https://mp.163.com") | 43 | await page.goto("https://mp.163.com") |
| 44 | + # await page.pause() | ||
| 45 | + # 点击调试器的继续,保存cookie | ||
| 46 | + # await context.storage_state(path=account_file) | ||
| 38 | 47 | ||
| 39 | - board = page.locator("//*[@class='homeV4__board__card__data__value']") | 48 | + # 自动登陆 |
| 40 | - # html_content = await board.inner_html() | ||
| 41 | - # print(html_content) | ||
| 42 | - content = await board.nth(0).inner_text() #总粉丝数 | ||
| 43 | - print(content) | ||
| 44 | - content = await board.nth(1).inner_text() #总阅读数 | ||
| 45 | - print(content) | ||
| 46 | - content = await board.nth(2).inner_text() #总收益 | ||
| 47 | - print(content) | ||
| 48 | - | ||
| 49 | - await page.get_by_text("粉丝数据").click() | ||
| 50 | - await page.wait_for_timeout(5000) | ||
| 51 | - await page.get_by_text("内容数据").click() | ||
| 52 | await page.wait_for_timeout(5000) | 49 | await page.wait_for_timeout(5000) |
| 53 | - await page.get_by_text("收益数据").click() | 50 | + frame = page.frame_locator('//iframe[contains(@id, "x-URS-iframe")]') |
| 51 | + await frame.locator('[name="email"]').fill('liufuhua007@163.com') | ||
| 52 | + await frame.locator('[name="password"]').fill("Liuyihong1023@") | ||
| 53 | + await frame.locator('#dologin').click() | ||
| 54 | + | ||
| 55 | + # await page.pause() | ||
| 54 | await page.wait_for_timeout(5000) | 56 | await page.wait_for_timeout(5000) |
| 55 | - browser.close() | 57 | + # 点击调试器的继续,保存cookie |
| 58 | + await context.storage_state(path=account_file) | ||
| 56 | 59 | ||
| 57 | 60 | ||
| 58 | async def get_wyh_cookie(account_file): | 61 | async def get_wyh_cookie(account_file): |
| 59 | - print("get_wyh_cookie") | ||
| 60 | async with async_playwright() as playwright: | 62 | async with async_playwright() as playwright: |
| 61 | options = { | 63 | options = { |
| 62 | 'args': [ | 64 | 'args': [ |
| ... | @@ -67,23 +69,47 @@ async def get_wyh_cookie(account_file): | ... | @@ -67,23 +69,47 @@ async def get_wyh_cookie(account_file): |
| 67 | # Make sure to run headed. | 69 | # Make sure to run headed. |
| 68 | browser = await playwright.chromium.launch(**options) | 70 | browser = await playwright.chromium.launch(**options) |
| 69 | # Setup context however you like. | 71 | # Setup context however you like. |
| 70 | - context = await browser.new_context() # Pass any options | 72 | + context = await browser.new_context(storage_state=account_file) # Pass any options |
| 71 | context = await set_init_script(context) | 73 | context = await set_init_script(context) |
| 72 | # Pause the page, and start recording manually. | 74 | # Pause the page, and start recording manually. |
| 73 | page = await context.new_page() | 75 | page = await context.new_page() |
| 74 | await page.goto("https://mp.163.com") | 76 | await page.goto("https://mp.163.com") |
| 75 | - # await page.pause() | 77 | + await page.pause() |
| 76 | - # 点击调试器的继续,保存cookie | 78 | + |
| 77 | - # await context.storage_state(path=account_file) | 79 | + |
| 80 | +async def open_wyh_main_page(account_file): | ||
| 81 | + async with async_playwright() as playwright: | ||
| 82 | + options = { | ||
| 83 | + 'args': [ | ||
| 84 | + '--lang en-GB' | ||
| 85 | + ], | ||
| 86 | + 'headless': False, # Set headless option here | ||
| 87 | + } | ||
| 88 | + # Make sure to run headed. | ||
| 89 | + browser = await playwright.chromium.launch(**options) | ||
| 90 | + # Setup context however you like. | ||
| 91 | + context = await browser.new_context(storage_state=account_file) # Pass any options | ||
| 92 | + context = await set_init_script(context) | ||
| 93 | + # Pause the page, and start recording manually. | ||
| 94 | + page = await context.new_page() | ||
| 95 | + await page.goto("https://mp.163.com") | ||
| 96 | + | ||
| 97 | + board = page.locator("//*[@class='homeV4__board__card__data__value']") | ||
| 98 | + # html_content = await board.inner_html() | ||
| 99 | + # print(html_content) | ||
| 100 | + content = await board.nth(0).inner_text() #总粉丝数 | ||
| 101 | + print(content) | ||
| 102 | + content = await board.nth(1).inner_text() #总阅读数 | ||
| 103 | + print(content) | ||
| 104 | + content = await board.nth(2).inner_text() #总收益 | ||
| 105 | + print(content) | ||
| 106 | + | ||
| 107 | + await page.get_by_text("粉丝数据").click() | ||
| 108 | + await page.wait_for_timeout(5000) | ||
| 109 | + await page.get_by_text("内容数据").click() | ||
| 110 | + await page.wait_for_timeout(5000) | ||
| 111 | + await page.get_by_text("收益数据").click() | ||
| 112 | + await page.wait_for_timeout(5000) | ||
| 113 | + browser.close() | ||
| 78 | 114 | ||
| 79 | - # 自动登陆 | ||
| 80 | - await page.wait_for_timeout(20000) | ||
| 81 | - frame = page.frame_locator('//iframe[contains(@id, "x-URS-iframe")]') | ||
| 82 | - await frame.locator('[name="email"]').fill('liufuhua007@163.com') | ||
| 83 | - await frame.locator('[name="password"]').fill("Liuyihong1023@") | ||
| 84 | - await frame.locator('#dologin').click() | ||
| 85 | 115 | ||
| 86 | - # await page.pause() | ||
| 87 | - await page.wait_for_timeout(15000) | ||
| 88 | - # 点击调试器的继续,保存cookie | ||
| 89 | - await context.storage_state(path=account_file) | ... | ... |
| ... | @@ -20,7 +20,7 @@ def get_supported_social_media() -> List[str]: | ... | @@ -20,7 +20,7 @@ def get_supported_social_media() -> List[str]: |
| 20 | 20 | ||
| 21 | 21 | ||
| 22 | def get_cli_action() -> List[str]: | 22 | def get_cli_action() -> List[str]: |
| 23 | - return ["upload", "login", "watch"] | 23 | + return ["upload", "login", "watch", "auto_login"] |
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | async def set_init_script(context): | 26 | async def set_init_script(context): | ... | ... |
-
Please register or login to post a comment