From 881725ac19acdf1c0ccb63a1383cd6b9aa249609 Mon Sep 17 00:00:00 2001 From: work Date: Thu, 17 Jul 2025 16:26:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E8=8E=B7=E5=8F=96=E5=A4=B4?= =?UTF-8?q?=E5=83=8F=E7=9A=84=E6=B5=81=E7=A8=8B=E6=9C=89=E4=BA=9B=E8=B4=A6?= =?UTF-8?q?=E5=8F=B7=E6=98=AF=E4=B8=AD=E6=96=87=E7=9A=84=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E5=88=86=E5=BC=80firstname=E5=92=8Clastname?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spider/task.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/spider/task.py b/spider/task.py index a27b80f..3398973 100644 --- a/spider/task.py +++ b/spider/task.py @@ -832,7 +832,8 @@ def check_account_status(page, cookies): raise AuthException('该账户登录状态失效', 'invalid') # 判断是否被检测到自动化,这种情况只需要点击按钮就可以继续 - if page.query_selector('//span[text()="We suspect automated behaviour on your account" or text()="We suspect automated behavior on your account"]') is not None: + if page.query_selector( + '//span[text()="We suspect automated behaviour on your account" or text()="We suspect automated behavior on your account"]') is not None: page.click('//span[text()="Dismiss"]') time.sleep(3) retry_goto(page, 'https://www.facebook.com') @@ -1052,7 +1053,7 @@ def playwright_get_user_profile(cookies, username=None): with sync_playwright() as playwright: update_windows_distinguish() browser = playwright.chromium.launch( - headless=True, args=['--start-maximized'], executable_path=path + headless=False, args=['--start-maximized'], executable_path=path ) context = browser.new_context(no_viewport=True) context.add_cookies(parse_cookies(cookies)) @@ -1060,15 +1061,20 @@ def playwright_get_user_profile(cookies, username=None): check_account_status(page, parse_cookies(cookies)) - url = 'https://facebook.com' + cookies_dict = {i['name']: i['value'] for i in parse_cookies(cookies)} + uid = cookies_dict["c_user"] + + url = f'https://accountscenter.facebook.com/profiles/{uid}' try: retry_goto(page, url) time.sleep(random.randint(3, 10)) - profile_pic_url = page.locator( - '//div[@aria-label="Shortcuts"]//li[1]//*[@preserveAspectRatio="xMidYMid slice"]').get_attribute( + profile_pic_url = page.query_selector('//*[@preserveAspectRatio="xMidYMid slice"]').get_attribute( 'xlink:href') - username = page.locator('//div[@aria-label="Shortcuts"]//li[1]//span').first.inner_text() + + page.query_selector('//div[@role="dialog"]//div[@role="listitem"]').click() + firstname = page.locator('//label[text()="First name"]/../input').input_value() + lastname = page.locator('//label[text()="Last name"]/../input').input_value() except Error as e: raise OperationFailed(f'操作超时,请重试{e}') context.close() @@ -1084,11 +1090,9 @@ def playwright_get_user_profile(cookies, username=None): # } ) bio = io.BytesIO(response.content) - key = f"{username.replace(' ', '_')}.png" + key = f"{lastname + firstname.replace(' ', '_')}.png" put_object(key, bio) - username_split = username.split(' ') - firstname, lastname = username_split[0], username_split[1] - return {'avatar_key': key, 'username': username, 'first_name': firstname, 'last_name': lastname} + return {'avatar_key': key, 'username': lastname + firstname, 'first_name': firstname, 'last_name': lastname} def playwright_set_user_profile(cookies, username=None, first_name=None, last_name=None, avatar_key=None): @@ -1539,9 +1543,9 @@ if __name__ == '__main__': # ) # cookies = '{"c_user":"61565405263653","datr":"-YDhZoLWu5zbUIw5cOB2In9s","fr":"0ZmsqLWbmV0Onlspt.AWW1JRfVxQAF-jl0oGY7lBQLYq4.Bm4YD5..AAA.0.0.Bm4YED.AWVf1ae03r4","m_page_voice":"61565405263653","m_pixel_ratio":"2.625","sb":"-YDhZs8LozUoyLe1gj2MCUwW","wd":"412x759","xs":"21%3A8Gt3CwtjVWJUhQ%3A2%3A1726054660%3A-1%3A-1"}' # cookies = '{"datr": "mm0taNtaPfOxWhpxdzpkVjV0", "sb": "mm0taFuFnO_L1FpzkKDiA4lw", "wd": "1920x953", "locale": "en_US", "c_user": "61575901481649", "fr": "0c0y2KyMv8lRJ6NNq.AWe7DLt-TSkoOyn3DhRjhA4ByOITAhfSwaiIw4eQE5ilq4Q4KAY.BoLW2a..AAA.0.0.BoLW3M.AWfHVOhZIAGgDh_3BvPFPi8-YhE", "xs": "29%3ASM0qc4U4Ile_MA%3A2%3A1747807693%3A-1%3A-1", "presence": "C%7B%22t3%22%3A%5B%5D%2C%22utc3%22%3A1747807698911%2C%22v%22%3A1%7D"}' - cookies = '{"locale": "en_US", "datr": "t4B0aLXWVdmlbB8Tk3DgGGAT", "sb": "t4B0aLcTJ8rVMlj5jSrGSxZ4", "m_pixel_ratio": "1", "wd": "1920x1080", "test_cookie": "CheckForPermission", "c_user": "61577826670230", "fr": "0npt8e8yXIwNJStkD.AWcQQE4Cfhhj6qesgxbHdF-QHPJH5JSMFUteWGNVP3fAvqnn1TQ.BodIC3..AAA.0.0.BodIDH.AWc9Ky_W-7IIpTEvkNAS8RwnJAU", "xs": "8%3APQt93fAQY1jbIw%3A2%3A1752465608%3A-1%3A-1"}' + cookies = '{"locale": "en_US", "datr": "PaB4aGZCgstQYUkBHpEVnEe8", "sb": "PaB4aAgR68sRQtATM6v7gEu5", "m_pixel_ratio": "1", "wd": "1920x1080", "test_cookie": "CheckForPermission", "c_user": "100094571602733", "fr": "0g0qqVhuLyyrKSaUv.AWdif7wExy29FD7aMjwFvrQFqoBzz-S7Qbeg8la4QMVeGv43eLg.BoeKA9..AAA.0.0.BoeKBQ.AWdj3k5XKtwF766wY3n-cro4yw8", "xs": "15%3A52m6IVmYaMzM3Q%3A2%3A1752735825%3A-1%3A-1"}' # print(playwright_share(cookies, "https://www.facebook.com/groups/1702958116839437/permalink/2210833932718517/", "")) - print(playwright_check_account_cookies(cookies)) + print(playwright_get_user_profile(cookies)) # # 永久链接的帖子点赞 # print(playwright_like(cookies, "https://www.facebook.com/groups/1070754870427928/permalink/1873461830157224/")) #