fix: 抖音因为设置地理位置可能造成的阻塞
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from playwright.async_api import Playwright, async_playwright
|
from playwright.async_api import Playwright, async_playwright, Page
|
||||||
import os
|
import os
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
@@ -160,15 +160,7 @@ class DouYinVideo(object):
|
|||||||
await asyncio.sleep(2)
|
await asyncio.sleep(2)
|
||||||
|
|
||||||
# 更换可见元素
|
# 更换可见元素
|
||||||
await page.locator('div.semi-select span:has-text("输入地理位置")').click()
|
await self.set_location(page, "杭州市")
|
||||||
await page.keyboard.press("Backspace")
|
|
||||||
await page.wait_for_timeout(2000)
|
|
||||||
# await page.keyboard.press("Control+KeyA")
|
|
||||||
# await page.keyboard.press("Delete")
|
|
||||||
await page.keyboard.type("杭州市")
|
|
||||||
# await asyncio.sleep(1)
|
|
||||||
await page.wait_for_timeout(1000)
|
|
||||||
await page.locator('div[role="listbox"] [role="option"]').first.click()
|
|
||||||
|
|
||||||
# 頭條/西瓜
|
# 頭條/西瓜
|
||||||
third_part_element = '[class^="info"] > [class^="first-part"] div div.semi-switch'
|
third_part_element = '[class^="info"] > [class^="first-part"] div div.semi-switch'
|
||||||
@@ -204,6 +196,14 @@ class DouYinVideo(object):
|
|||||||
await context.close()
|
await context.close()
|
||||||
await browser.close()
|
await browser.close()
|
||||||
|
|
||||||
|
async def set_location(self, page: Page, location: str = "杭州市"):
|
||||||
|
await page.locator('div.semi-select span:has-text("输入地理位置")').click()
|
||||||
|
await page.keyboard.press("Backspace")
|
||||||
|
await page.wait_for_timeout(2000)
|
||||||
|
await page.keyboard.type(location)
|
||||||
|
await page.wait_for_selector('div[role="listbox"] [role="option"]', timeout=5000)
|
||||||
|
await page.locator('div[role="listbox"] [role="option"]').first.click()
|
||||||
|
|
||||||
async def main(self):
|
async def main(self):
|
||||||
async with async_playwright() as playwright:
|
async with async_playwright() as playwright:
|
||||||
await self.upload(playwright)
|
await self.upload(playwright)
|
||||||
|
|||||||
Reference in New Issue
Block a user