Created
July 11, 2024 16:49
-
-
Save devniel/6cd650b97c5589b9fe4944d96e5d4bab to your computer and use it in GitHub Desktop.
Remove twitter bot followers
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 characters
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"]}") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment