rpa m
This commit is contained in:
parent
a785e4fc63
commit
6cdcf154a7
|
|
@ -160,6 +160,8 @@ async def get_promotion_list_text(page: Page, result: LiveStreamResult,
|
||||||
|
|
||||||
"""
|
"""
|
||||||
logger.debug(f"get_promotion_list_text result: {result}")
|
logger.debug(f"get_promotion_list_text result: {result}")
|
||||||
|
await page.wait_for_load_state(state='networkidle')
|
||||||
|
logger.debug(f"networkidle,get_promotion_list_text result: {result}")
|
||||||
product_name_js, promotion_list_js = await init_load(page)
|
product_name_js, promotion_list_js = await init_load(page)
|
||||||
|
|
||||||
product_sessions: List[ProductSession] = [] # List of ProductSession objects
|
product_sessions: List[ProductSession] = [] # List of ProductSession objects
|
||||||
|
|
@ -346,7 +348,7 @@ async def do_explaining(current_product_id, current_product_img, current_product
|
||||||
return current_product_id, current_product_img, current_product_name, last_live_time, start_time
|
return current_product_id, current_product_img, current_product_name, last_live_time, start_time
|
||||||
|
|
||||||
|
|
||||||
async def refresh_page(page):
|
async def refresh_page(page:Page):
|
||||||
try:
|
try:
|
||||||
# await page.reload(timeout=60000)
|
# await page.reload(timeout=60000)
|
||||||
# await page.wait_for_load_state("networkidle", timeout=60000)
|
# await page.wait_for_load_state("networkidle", timeout=60000)
|
||||||
|
|
@ -360,13 +362,13 @@ async def refresh_page(page):
|
||||||
# )
|
# )
|
||||||
|
|
||||||
svg = page.locator('#__living_right_panel_id svg').first
|
svg = page.locator('#__living_right_panel_id svg').first
|
||||||
svg.click()
|
await svg.click()
|
||||||
print("已点击关闭标签的 SVG 图标")
|
print("已点击关闭标签的 SVG 图标")
|
||||||
page.wait_for_timeout(3 * 1000)
|
await page.wait_for_timeout(3 * 1000)
|
||||||
|
|
||||||
page.get_by_text("全部商品").click()
|
await page.get_by_text("全部商品").click()
|
||||||
print("已点击 全部商品 ")
|
print("已点击 全部商品 ")
|
||||||
page.wait_for_timeout(3 * 1000)
|
await page.wait_for_timeout(3 * 1000)
|
||||||
|
|
||||||
# page.get_by_text("继续播放").click()
|
# page.get_by_text("继续播放").click()
|
||||||
# page.wait_for_timeout(3 * 000)
|
# page.wait_for_timeout(3 * 000)
|
||||||
|
|
@ -454,7 +456,8 @@ with (rpa_image.imports()):
|
||||||
@app.function(timeout=8 * 60 * 60, volumes={"/data": rpa_vol}, cloud="gcp", region="ap")
|
@app.function(timeout=8 * 60 * 60, volumes={"/data": rpa_vol}, cloud="gcp", region="ap")
|
||||||
async def rpa_new(data: LiveStreamProductWatchRequest):
|
async def rpa_new(data: LiveStreamProductWatchRequest):
|
||||||
webcast_id = data.live_id
|
webcast_id = data.live_id
|
||||||
url = f"https://live.douyin.com/{webcast_id}?open_promotion_list=1"
|
# url = f"https://live.douyin.com/{webcast_id}?open_promotion_list=1"
|
||||||
|
url = f"https://live.douyin.com/{webcast_id}"
|
||||||
print(url)
|
print(url)
|
||||||
async with async_playwright() as p:
|
async with async_playwright() as p:
|
||||||
browser: Browser = await p.chromium.launch(headless=True, channel='msedge')
|
browser: Browser = await p.chromium.launch(headless=True, channel='msedge')
|
||||||
|
|
@ -535,7 +538,8 @@ with (rpa_image.imports()):
|
||||||
await context.add_cookies(cookies)
|
await context.add_cookies(cookies)
|
||||||
logger.info("Loaded cookies")
|
logger.info("Loaded cookies")
|
||||||
page: Page = await context.new_page()
|
page: Page = await context.new_page()
|
||||||
url = f"https://live.douyin.com/{webcast_id}?open_promotion_list=1&from_search=true"
|
# url = f"https://live.douyin.com/{webcast_id}?open_promotion_list=1&from_search=true"
|
||||||
|
url = f"https://live.douyin.com/{webcast_id}"
|
||||||
logger.info(f"Navigating to {url}")
|
logger.info(f"Navigating to {url}")
|
||||||
await page.goto(url, wait_until="domcontentloaded")
|
await page.goto(url, wait_until="domcontentloaded")
|
||||||
logger.info(f"Navigating to end {url}")
|
logger.info(f"Navigating to end {url}")
|
||||||
|
|
@ -543,6 +547,10 @@ with (rpa_image.imports()):
|
||||||
result.title = await page.title()
|
result.title = await page.title()
|
||||||
logger.info(f"------Retrieved title: {result.title}")
|
logger.info(f"------Retrieved title: {result.title}")
|
||||||
|
|
||||||
|
await page.get_by_text("全部商品").click()
|
||||||
|
print("已点击 全部商品 ")
|
||||||
|
await page.wait_for_timeout(3 * 1000)
|
||||||
|
|
||||||
live_status = await get_live_status_by_web_page(page, webcast_id)
|
live_status = await get_live_status_by_web_page(page, webcast_id)
|
||||||
|
|
||||||
if live_status == LIVE_END:
|
if live_status == LIVE_END:
|
||||||
|
|
@ -560,9 +568,9 @@ with (rpa_image.imports()):
|
||||||
|
|
||||||
|
|
||||||
@retry(stop=stop_after_attempt(50), wait=wait_fixed(5))
|
@retry(stop=stop_after_attempt(50), wait=wait_fixed(5))
|
||||||
async def wait_for_load_state_foo(page, url):
|
async def wait_for_load_state_foo(page: Page, url):
|
||||||
logger.info(f"networkidle to start {url}")
|
logger.info(f"networkidle to start {url}")
|
||||||
await page.wait_for_load_state("networkidle", timeout=5 * 1000)
|
await page.wait_for_load_state(state="load")
|
||||||
logger.info(f"networkidle to end {url}")
|
logger.info(f"networkidle to end {url}")
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
@ -574,7 +582,7 @@ with (rpa_image.imports()):
|
||||||
# 312898731614
|
# 312898731614
|
||||||
# webcast_ids = ["36861064178"]
|
# webcast_ids = ["36861064178"]
|
||||||
# webcast_ids = ["36861064178"]
|
# webcast_ids = ["36861064178"]
|
||||||
webcast_id = "65731953339"
|
webcast_id = "837842834415"
|
||||||
|
|
||||||
data: LiveStreamProductWatchRequest = LiveStreamProductWatchRequest(live_id=webcast_id,
|
data: LiveStreamProductWatchRequest = LiveStreamProductWatchRequest(live_id=webcast_id,
|
||||||
live_stream_name=str(ULID()))
|
live_stream_name=str(ULID()))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue