diff --git a/spider/task.py b/spider/task.py index d9d33ff..cd89ae8 100644 --- a/spider/task.py +++ b/spider/task.py @@ -255,22 +255,20 @@ def playwright_post(cookies, content, image_key=None): filename = image_key.split('/')[-1] file_path = os.path.join(BASE_PATH, 'files', filename) client.fget_object(BUCKET, image_key, file_path) - page.click('//span[text()="Photo/video"]') + sleep(1, 2) - with page.expect_file_chooser() as fc_info: - page.click('//span[text()="Add photos/videos"]') - file_chooser = fc_info.value - file_chooser.set_files(file_path) + page.locator('input[accept="image/*,image/heif,image/heic,video/*,video/mp4,video/x-m4v,' + 'video/x-matroska,.mkv"]').set_input_files(file_path) time.sleep(5) if not image_key: page.click('''//span[contains(text(), "What's on your mind")]''') _edit_privacy(page) page.type('''//div[contains(@aria-placeholder, "What's on your mind")]''', content, delay=50) - page.click('//div[@aria-label="Post"]') + page.click('//div[@aria-label="Post"]', timeout=300000) time.sleep(15) post_index = page.locator('//div[@aria-posinset="1"]//a[@role="link"]').nth(2) - post_index.click() + post_index.click(timeout=600000) time.sleep(5) page.reload() post_url = page.url