发帖后获取帖子url
This commit is contained in:
@@ -819,7 +819,7 @@ def playwright_post(cookies, message, 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.download_file(BUCKET, image_key, file_path)
|
client.download_file(BUCKET, image_key, file_path)
|
||||||
page.click('//div[@aria-label="Photo/video"]')
|
page.click('//span[text()="Photo/video"]')
|
||||||
sleep(1, 2)
|
sleep(1, 2)
|
||||||
with page.expect_file_chooser() as fc_info:
|
with page.expect_file_chooser() as fc_info:
|
||||||
page.click('//span[text()="Add photos/videos"]')
|
page.click('//span[text()="Add photos/videos"]')
|
||||||
@@ -827,13 +827,20 @@ def playwright_post(cookies, message, image_key=None):
|
|||||||
file_chooser.set_files(file_path)
|
file_chooser.set_files(file_path)
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
|
||||||
|
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-label, "What's on your mind")]''', message)
|
page.type('''//div[contains(@aria-label, "What's on your mind")]''', message)
|
||||||
|
|
||||||
page.click('//div[@aria-label="Post"]')
|
page.click('//div[@aria-label="Post"]')
|
||||||
|
time.sleep(15)
|
||||||
|
|
||||||
|
post_url = page.locator('//div[@data-pagelet="FeedUnit_0"]//a[@role="link"]').nth(2).get_attribute('href')
|
||||||
|
if '&__cft__' in post_url:
|
||||||
|
post_url = post_url.split('&__cft__')[0]
|
||||||
context.close()
|
context.close()
|
||||||
browser.close()
|
browser.close()
|
||||||
|
return {'resp_id': post_url}
|
||||||
|
|
||||||
|
|
||||||
def playwright_comment(cookies, post_id, message, image_key=None):
|
def playwright_comment(cookies, post_id, message, image_key=None):
|
||||||
@@ -988,6 +995,28 @@ def playwright_set_user_profile(cookies, firstname=None, lastname=None, image_ke
|
|||||||
browser.close()
|
browser.close()
|
||||||
|
|
||||||
|
|
||||||
|
def playwright_test(cookies):
|
||||||
|
path = os.path.join(BASE_PATH, 'chrome', '130-0008', 'chrome.exe')
|
||||||
|
with lock:
|
||||||
|
with sync_playwright() as playwright:
|
||||||
|
update_windows_distinguish()
|
||||||
|
browser = playwright.chromium.launch(
|
||||||
|
headless=False, args=['--start-maximized'], executable_path=path
|
||||||
|
# proxy=dove_proxy.get_playwright_proxy(get_storage(cookies, 'username'))
|
||||||
|
)
|
||||||
|
context = browser.new_context(no_viewport=True)
|
||||||
|
context.add_init_script(path=os.path.join(BASE_PATH, 'stealth.min.js'))
|
||||||
|
context.add_cookies([
|
||||||
|
{'name': k, 'value': v, 'domain': '.facebook.com', 'path': '/'} for k, v in cookies.items()
|
||||||
|
])
|
||||||
|
page = context.new_page()
|
||||||
|
url = 'https://www.facebook.com'
|
||||||
|
page.goto(url)
|
||||||
|
time.sleep(10000)
|
||||||
|
context.close()
|
||||||
|
browser.close()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# cookies = {
|
# cookies = {
|
||||||
# 'datr': 'gUM7ZgtRENjtL34mDqlmAhD6',
|
# 'datr': 'gUM7ZgtRENjtL34mDqlmAhD6',
|
||||||
@@ -1010,11 +1039,12 @@ if __name__ == '__main__':
|
|||||||
'fr': '04xfKMRdCsbtllhPA.AWUt-rPOi-ist5ZdVHl3jiYcKYM11xLu0MN9gA.Bn4MXg..AAA.0.0.Bn4MYY.AWWmAFxhQek',
|
'fr': '04xfKMRdCsbtllhPA.AWUt-rPOi-ist5ZdVHl3jiYcKYM11xLu0MN9gA.Bn4MXg..AAA.0.0.Bn4MYY.AWWmAFxhQek',
|
||||||
'xs': '6:he_0XMG7YzQPKQ:2:1742784022:-1:-1',
|
'xs': '6:he_0XMG7YzQPKQ:2:1742784022:-1:-1',
|
||||||
}
|
}
|
||||||
|
# playwright_test(cookies)
|
||||||
# post(cookies, 'cs2025')
|
# post(cookies, 'cs2025')
|
||||||
# like(cookies, 'ZmVlZGJhY2s6MTIyMTA5NjE0NjU0NzkzNzc5')
|
# like(cookies, 'ZmVlZGJhY2s6MTIyMTA5NjE0NjU0NzkzNzc5')
|
||||||
# comment(cookies, 'ZmVlZGJhY2s6MTIyMTA5NjE0NjU0NzkzNzc5', 'game la', 'facebook/xzpq.mp4')
|
# comment(cookies, 'ZmVlZGJhY2s6MTIyMTA5NjE0NjU0NzkzNzc5', 'game la', 'facebook/xzpq.mp4')
|
||||||
# playwright_like(cookies, 'https://www.facebook.com/watch/?v=1007800324567828')
|
# playwright_like(cookies, 'https://www.facebook.com/watch/?v=1007800324567828')
|
||||||
|
# print(playwright_post(cookies, '2025-3-230~like'))
|
||||||
# playwright_post(cookies, '2025-3-26~like', 'face/rg.jpg')
|
# playwright_post(cookies, '2025-3-26~like', 'face/rg.jpg')
|
||||||
# playwright_comment(
|
# playwright_comment(
|
||||||
# cookies,
|
# cookies,
|
||||||
@@ -1031,3 +1061,4 @@ if __name__ == '__main__':
|
|||||||
# lastname='Keals',
|
# lastname='Keals',
|
||||||
# image_key='facebook/rg.jpg'
|
# image_key='facebook/rg.jpg'
|
||||||
# )
|
# )
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user