修复发帖带文件失败的问题

This commit is contained in:
Your Name
2025-08-20 21:11:08 +08:00
parent 2b2bcbebb4
commit 200eef7dcd

View File

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