Created
July 11, 2024 16:49
-
-
Save devniel/6cd650b97c5589b9fe4944d96e5d4bab to your computer and use it in GitHub Desktop.
Revisions
-
devniel renamed this gist
Jul 11, 2024 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
devniel created this gist
Jul 11, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ from playwright.sync_api import sync_playwright with sync_playwright() as p: browser = p.chromium.connect_over_cdp("http://localhost:9222") default_context = browser.contexts[0] page = default_context.pages[0] page.goto("https://x.com/devniel/followers") page.wait_for_timeout(1000) items = page.get_by_test_id("cellInnerDiv").all() print(len(items)) # Get all followers in the page users = [] for item in items: links = item.get_by_role("link").all() name = links[0].text_content() username = links[1].text_content().lstrip("@") print(f"{name} | {username}") users.append({ "name": name, "username": username }) # Visit all followers profile page for user in users: print(user) page.goto(f"https://x.com/{user["username"]}")