diff --git a/spider/task.py b/spider/task.py index 2199942..27d5274 100644 --- a/spider/task.py +++ b/spider/task.py @@ -291,7 +291,7 @@ def playwright_like(cookies, target_url): retry_goto(page, url) time.sleep(random.randint(3, 10)) - if 'permalink.php?story_fbid' in target_url or '/permalink/' in target_url or '/posts/' in target_url: + if 'permalink.php?story_fbid' in target_url or '/permalink/' in target_url or '/posts/' in target_url: # 文字或图片类型 button_xpath = '//*[@role="dialog"]//span[text()="Like" or @data-ad-rendering-role="like_button"]' elif 'watch/?v' in target_url or '/videos/' in target_url: @@ -985,10 +985,14 @@ def playwright_share(cookies, target_url, content): retry_goto(page, target_url) if 'permalink.php?story_fbid' in target_url or '/posts/' in target_url or "/permalink/" in target_url: # 文字或图片类型 - share_button = '//div[@aria-label="Send this to friends or post it on your profile."]//span[@data-ad-rendering-role="share_button"]' + share_button = page.query_selector( + '//*[@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"]' - page.locator(share_button).last.click() + share_button.scroll_into_view_if_needed() + page.evaluate("(element) => element.click()", share_button) + time.sleep(1) + elif 'watch/?v' in target_url or '/videos/' in target_url or 'watch?v' in target_url: # 视频类型, 视频类型, share_button = '//span[@dir="auto" and text()="Share"]' @@ -1036,7 +1040,10 @@ def playwright_share(cookies, target_url, content): if __name__ == '__main__': # cookies = '{"locale": "en_US", "datr": "ZnGnaBBx0yN7pov19-8_A6Gr", "sb": "ZnGnaDQicDSsVuevkudqio1J", "m_pixel_ratio": "1", "wd": "1920x1080", "test_cookie": "CheckForPermission", "c_user": "61579364283503", "xs": "34%3AdWeZoaWzFrtdVQ%3A2%3A1755804022%3A-1%3A-1", "oo": "v1%7C3%3A1755804031"}' # cookies = {"c_user":"61565823476070","datr":"q13hZowje6bbViFxECQpYyp8","fr":"01C6Lt4VArm5hELvx.AWXg75HOo-QNJgbiDl8qFtw_5lc.Bm4V2r..AAA.0.0.Bm4V25.AWWHzUeMTuI","m_pixel_ratio":"1.875","sb":"q13hZgJARsRIDmNJG8xUauAe","wd":"384x686","xs":"50%3A8luhgQ-Ea0vnhg%3A2%3A1726045627%3A-1%3A-1"} - cookies = {"locale": "en_US", "datr": "vBmxaKfb6cm0AhcefMHPSQO6", "sb": "vBmxaGdLX0gW8f4-cRs7nUtk", "m_pixel_ratio": "1", "wd": "1920x1080", "test_cookie": "CheckForPermission", "c_user": "61552034433240", "fr": "0WwHWIVyPWFnUQJdK.AWc47U27HRH3lkVnoI2aLvYmWh9OtMnXPu_1tPSnENGUyO5p_4M.BosRm8..AAA.0.0.BosRnW.AWeWlm_2ZdtbsqcgNZYOw4T5QaI", "xs": "15%3AGhxgmwl-LvPNow%3A2%3A1756436950%3A-1%3A-1"} + cookies = {"locale": "en_US", "datr": "vBmxaKfb6cm0AhcefMHPSQO6", "sb": "vBmxaGdLX0gW8f4-cRs7nUtk", + "m_pixel_ratio": "1", "wd": "1920x1080", "test_cookie": "CheckForPermission", "c_user": "61552034433240", + "fr": "0WwHWIVyPWFnUQJdK.AWc47U27HRH3lkVnoI2aLvYmWh9OtMnXPu_1tPSnENGUyO5p_4M.BosRm8..AAA.0.0.BosRnW.AWeWlm_2ZdtbsqcgNZYOw4T5QaI", + "xs": "15%3AGhxgmwl-LvPNow%3A2%3A1756436950%3A-1%3A-1"} # post(cookies, 'cs2025') # like(cookies, 'ZmVlZGJhY2s6MTIyMTA5NjE0NjU0NzkzNzc5') # comment(cookies, 'ZmVlZGJhY2s6MTIyMTA5NjE0NjU0NzkzNzc5', 'game la', 'xzpq.mp4') @@ -1068,7 +1075,9 @@ if __name__ == '__main__': # print(playwright_get_user_profile(cookies)) # # 永久链接的帖子点赞 # print(playwright_like(cookies, "https://www.facebook.com/groups/1070754870427928/permalink/1873461830157224/")) - print(playwright_like(cookies, "https://www.facebook.com/groups/267112859525987/permalink/658047397099196/?rdid=LETw8B1KYb7eUKUJ")) + print(playwright_share(cookies, + "https://www.facebook.com/permalink.php?story_fbid=pfbid02BMYFCJTTG7WedezZzRn6YFEbrBg4gpUJKExMLTTdZycQFF2wuhbr8oWvmvUBiKTNl&id=61556406998616", + "郭正亮痛斥賴清德笑什麼,全台灣都想問")) # # # # 视频链接的帖子点赞 # print(playwright_like(cookies, "https://www.facebook.com/groups/1070754870427928/permalink/1873461830157224/"))