Skip to content

Instantly share code, notes, and snippets.

@devniel
Created July 11, 2024 16:49
Show Gist options
  • Select an option

  • Save devniel/6cd650b97c5589b9fe4944d96e5d4bab to your computer and use it in GitHub Desktop.

Select an option

Save devniel/6cd650b97c5589b9fe4944d96e5d4bab to your computer and use it in GitHub Desktop.

Revisions

  1. devniel renamed this gist Jul 11, 2024. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. devniel created this gist Jul 11, 2024.
    26 changes: 26 additions & 0 deletions gistfile1.txt
    Original 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"]}")