转发灰度页面也能正常执行
All checks were successful
Update Code / StopService (windows-101.36.102.136) (push) Successful in 1s
Update Code / StopService (windows-101.36.104.175) (push) Successful in 1s
Update Code / CD (windows-101.36.102.136) (push) Successful in 11s
Update Code / CD (windows-101.36.104.175) (push) Successful in 25s
All checks were successful
Update Code / StopService (windows-101.36.102.136) (push) Successful in 1s
Update Code / StopService (windows-101.36.104.175) (push) Successful in 1s
Update Code / CD (windows-101.36.102.136) (push) Successful in 11s
Update Code / CD (windows-101.36.104.175) (push) Successful in 25s
This commit is contained in:
@@ -319,6 +319,7 @@ def is_post_liked_in_dialog(page):
|
||||
print("未找到点赞按钮")
|
||||
return False
|
||||
|
||||
|
||||
def playwright_like(cookies, target_url):
|
||||
path = os.path.join(BASE_PATH, 'chrome', '130-0008', 'chrome.exe')
|
||||
with lock:
|
||||
@@ -442,8 +443,8 @@ def retry_get_new_video(page, cookies, post_count):
|
||||
TimeoutError: 超时未获取到新视频
|
||||
OperationFailed: 点击视频时出错
|
||||
"""
|
||||
max_duration = 10 * 60 # 5分钟(300秒)
|
||||
retry_interval = 30 # 30秒重试一次
|
||||
max_duration = 10 * 60 # 5分钟(300秒)
|
||||
retry_interval = 30 # 30秒重试一次
|
||||
start_time = time.time()
|
||||
attempt = 1
|
||||
|
||||
@@ -614,9 +615,9 @@ def _is_facebook_home(page):
|
||||
def _get_share_config(target_url):
|
||||
if 'permalink.php?story_fbid' in target_url or '/posts/' in target_url or '/permalink/' in target_url:
|
||||
return {
|
||||
'share_button': '//*[@role="dialog"]//div[@data-ad-rendering-role="share_button"]',
|
||||
'input_box': '//form[@method="POST" and count(@*) = 1]/div/div/div[2]',
|
||||
'share_now_button': '//span[text()="Share now"]',
|
||||
'share_button': '//*[@role="dialog"]//div[@aria-label="Send this to friends or post it on your profile."]',
|
||||
'input_box': "//div[contains(@aria-placeholder, \"What's on your mind\")] | //div[contains(@aria-placeholder, \"Say something about this\")]",
|
||||
'share_now_button': '//*[@role="dialog"]//div[@role="button" and @aria-label="Share now"] | //*[@role="dialog"]//div[@aria-label="Share"]',
|
||||
}
|
||||
if 'watch/?v' in target_url or '/videos/' in target_url or 'watch?v' in target_url:
|
||||
return {
|
||||
@@ -635,37 +636,23 @@ def _get_share_config(target_url):
|
||||
|
||||
def _click_share_button(page, selector):
|
||||
locator = page.locator(selector)
|
||||
deadline = time.time() + 120
|
||||
locator.wait_for()
|
||||
count = locator.count()
|
||||
|
||||
while time.time() < deadline:
|
||||
count = locator.count()
|
||||
for index in range(count):
|
||||
candidate = locator.nth(index)
|
||||
try:
|
||||
if candidate.is_visible():
|
||||
candidate.scroll_into_view_if_needed(timeout=30000)
|
||||
candidate.click(timeout=60000)
|
||||
return
|
||||
except Error:
|
||||
for index in range(count):
|
||||
candidate = locator.nth(index)
|
||||
try:
|
||||
if not candidate.is_visible():
|
||||
continue
|
||||
page.wait_for_timeout(1000)
|
||||
candidate.click(timeout=3000, trial=True)
|
||||
candidate.click(timeout=5000)
|
||||
page.wait_for_timeout(1000)
|
||||
|
||||
element = page.query_selector(selector)
|
||||
if element is None:
|
||||
raise OperationFailed(f'未找到分享按钮: {selector}')
|
||||
return
|
||||
except Error:
|
||||
continue
|
||||
|
||||
page.evaluate(
|
||||
"""(node) => {
|
||||
const clickable =
|
||||
node.closest('[role="button"]') ||
|
||||
node.closest('[aria-label]') ||
|
||||
node.parentElement ||
|
||||
node;
|
||||
clickable.click();
|
||||
}""",
|
||||
element
|
||||
)
|
||||
page.wait_for_timeout(1000)
|
||||
raise OperationFailed(f'未找到可点击的分享按钮: {selector}')
|
||||
|
||||
|
||||
def _fill_share_content(page, selector, content):
|
||||
@@ -726,9 +713,7 @@ def _submit_share(page, selector):
|
||||
share_now_button = page.locator(selector).first
|
||||
share_now_button.wait_for(state='visible', timeout=60000)
|
||||
share_now_button.click(timeout=60000)
|
||||
page.wait_for_selector('//span[text()="Posting..."]', state='detached', timeout=180000)
|
||||
page.wait_for_selector('//span[text()="Shared to your profile"]', timeout=180000)
|
||||
|
||||
page.wait_for_timeout(15000)
|
||||
|
||||
def playwright_post(cookies, content, image_key=None, dry_run=False):
|
||||
path = os.path.join(BASE_PATH, 'chrome', '130-0008', 'chrome.exe')
|
||||
@@ -768,7 +753,9 @@ def playwright_post(cookies, content, image_key=None, dry_run=False):
|
||||
if image_key:
|
||||
file_path = _download_post_media(image_key)
|
||||
sleep(1, 2)
|
||||
page.locator('input[accept="image/*,image/heif,image/heic,video/*,video/mp4,video/x-m4v,video/x-matroska,.mkv"]').set_input_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)
|
||||
page.locator('//div[contains(@aria-placeholder, "What\'s on your mind")]').first.wait_for(
|
||||
state='visible', timeout=300000
|
||||
)
|
||||
@@ -1489,6 +1476,37 @@ def playwright_share(cookies, target_url, content):
|
||||
retry_goto(page, target_url)
|
||||
share_config = _get_share_config(target_url)
|
||||
_click_share_button(page, share_config['share_button'])
|
||||
if 'permalink.php?story_fbid' in target_url or '/posts/' in target_url or '/permalink/' in target_url:
|
||||
if page.query_selector(
|
||||
'//*[@role="dialog"]//h2/span[text()="Share"]') is None:
|
||||
if page.query_selector('//*[@role="dialog" and @aria-label="Share options"]'):
|
||||
page.query_selector(
|
||||
'//*[@role="dialog" and @aria-label="Share options"]//span[text()="Share to Feed"]').click()
|
||||
# 判断是否有弹窗
|
||||
if page.query_selector('//*[@role="dialog"]//span[@id="_R_imjbsmj5ilipam_"]'):
|
||||
try:
|
||||
# 点击返回
|
||||
page.wait_for_selector(
|
||||
'//*[@role="dialog"]//div[@aria-label="Continue"]',
|
||||
state='visible',
|
||||
timeout=5000
|
||||
)
|
||||
continue_btn = page.query_selector('//*[@role="dialog"]//div[@aria-label="Continue"]')
|
||||
if continue_btn is not None:
|
||||
continue_btn.click()
|
||||
|
||||
# 点击Done
|
||||
page.wait_for_selector(
|
||||
'//*[@role="dialog"]//div[@aria-label="Done with privacy audience selection and close dialog"]',
|
||||
state='visible',
|
||||
timeout=5000
|
||||
)
|
||||
done_btn = page.query_selector('//*[@role="dialog"]//div[@aria-label="Done with privacy audience selection and close dialog"]')
|
||||
if done_btn is not None:
|
||||
done_btn.click()
|
||||
except TimeoutError:
|
||||
pass
|
||||
|
||||
_fill_share_content(page, share_config['input_box'], content)
|
||||
_edit_privacy(page)
|
||||
_submit_share(page, share_config['share_now_button'])
|
||||
@@ -1539,7 +1557,13 @@ def playwright_share(cookies, target_url, content):
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
cookies = {"c_user":"61585626484995","datr":"NGBPadlTOQH5fwTPcUTGtLI5","dpr":"0.3400000035762787","fr":"0OHgdNICbgL23ZzCq..BptI5c..AAA.0.0.BptI5l.AWf9nkRp50sAbeHCdwhX--SsOVA","m_pixel_ratio":"0.3400000035762787","ps_l":"1","ps_n":"1","sb":"-Y-0adE6TkW7Fd070vzZxn5H","useragent":"TW96aWxsYS81LjAgKExpbnV4OyBBbmRyb2lkIDEwOyBGaW5kIFg1IFBybyBCdWlsZC9UUDFBLjIyMTAwNS4wMDI7IHd2KSBBcHBsZVdlYktpdC81MzcuMzYgKEtIVE1MLCBsaWtlIEdlY2tvKSBWZXJzaW9uLzQuMCBDaHJvbWUvMTI3LjAuMC4wIE1vYmlsZSBTYWZhcmkvNTM3LjM2IFtGQkFOL0VNQTtGQkxDL2VuX1VTO0ZCQVYvNDE5LjAuMC4xMC4xMjA7XQ%3D%3D","wd":"500x402","x-referer":"eyJyIjoiL3NlY3VyaXR5LzJmYWMvc2V0dXAvcXJjb2RlL2dlbmVyYXRlLz9leHQ9MTc3MzcwMDE2NiZoYXNoPUFlY2Vld0J0M0Q3UnhaMDgwTVBYMHR0UDFKUSIsImgiOiIvc2VjdXJpdHkvMmZhYy9zZXR1cC9xcmNvZGUvZ2VuZXJhdGUvP2V4dD0xNzczNzAwMTY2Jmhhc2g9QWVjZWV3QnQzRDdSeFowODBNUFgwdHRQMUpRIiwicyI6Im0ifQ%3D%3D","xs":"42:KzK0Y_fjLkJzUQ:2:1766809815:-1:-1"}
|
||||
cookies = {"c_user": "61585626484995", "datr": "NGBPadlTOQH5fwTPcUTGtLI5", "dpr": "0.3400000035762787",
|
||||
"fr": "0OHgdNICbgL23ZzCq..BptI5c..AAA.0.0.BptI5l.AWf9nkRp50sAbeHCdwhX--SsOVA",
|
||||
"m_pixel_ratio": "0.3400000035762787", "ps_l": "1", "ps_n": "1", "sb": "-Y-0adE6TkW7Fd070vzZxn5H",
|
||||
"useragent": "TW96aWxsYS81LjAgKExpbnV4OyBBbmRyb2lkIDEwOyBGaW5kIFg1IFBybyBCdWlsZC9UUDFBLjIyMTAwNS4wMDI7IHd2KSBBcHBsZVdlYktpdC81MzcuMzYgKEtIVE1MLCBsaWtlIEdlY2tvKSBWZXJzaW9uLzQuMCBDaHJvbWUvMTI3LjAuMC4wIE1vYmlsZSBTYWZhcmkvNTM3LjM2IFtGQkFOL0VNQTtGQkxDL2VuX1VTO0ZCQVYvNDE5LjAuMC4xMC4xMjA7XQ%3D%3D",
|
||||
"wd": "500x402",
|
||||
"x-referer": "eyJyIjoiL3NlY3VyaXR5LzJmYWMvc2V0dXAvcXJjb2RlL2dlbmVyYXRlLz9leHQ9MTc3MzcwMDE2NiZoYXNoPUFlY2Vld0J0M0Q3UnhaMDgwTVBYMHR0UDFKUSIsImgiOiIvc2VjdXJpdHkvMmZhYy9zZXR1cC9xcmNvZGUvZ2VuZXJhdGUvP2V4dD0xNzczNzAwMTY2Jmhhc2g9QWVjZWV3QnQzRDdSeFowODBNUFgwdHRQMUpRIiwicyI6Im0ifQ%3D%3D",
|
||||
"xs": "42:KzK0Y_fjLkJzUQ:2:1766809815:-1:-1"}
|
||||
# print(playwright_check_account_cookies(cookies))
|
||||
# print(playwright_set_user_profile(cookies, "61584735094876", "Inaaya", "Inaaya",
|
||||
# "facebook/user_upload/0196f098-851c-7810-b2aa-0833a0a7b09d/8c428558-2d90-4f45-baa3-a25f8a654b5c.png"))
|
||||
|
||||
Reference in New Issue
Block a user