Skip to content

Latest commit

 

History

History
151 lines (101 loc) · 3.94 KB

README.md

File metadata and controls

151 lines (101 loc) · 3.94 KB

🚀 x-web-crawler

x-web-crawler is a Python package for automating interactions on X.

Installation

You can install x-web-crawler using pip:

pip install x-web-crawler

Usage

Here’s an example of how to use x-web-crawler to automate actions on Twitter (X) and GitHub:

from xagent import XAgent

def main():
    driver_path = "YOUR_DRIVER_PATH"
    profile_path = "YOUR_PROFILE_PATH"
    twitter_username = "YOUR_TWITTER_USERNAME" # works best with your X handle and not email
    twitter_password = "YOUR_TWITTER_PASSWORD"

    agent = XAgent(
        driver_path=driver_path,
        profile_path=profile_path,
        x_username=twitter_username,
        x_password=twitter_password,
    )

    try:
        agent.like_x_posts(duration=300)
        agent.follow_x_users(["https://x.com/jacob_somer_"], duration=300)
    finally:
        agent.close()

if __name__ == "__main__":
    main()

Examples

Automating Twitter (X) Actions

Here's how to automate actions on Twitter (X) using the Chrome browser:

from xagent import XAgent

driver_path = "/Users/jacobsomer/Documents/side_prod/salesBook/chromedriver-mac-arm64/chromedriver"
profile_path = "/Users/jacobsomer/Library/Application Support/Google/Chrome/chromeProfile"
x_username = "YOUR_TWITTER_USERNAME"
x_password = "YOUR_TWITTER_PASSWORD"

agent = XAgent(
    driver_path=driver_path,
    profile_path=profile_path,
    x_username=x_username,
    x_password=x_password,
)

try:
    # Like posts on your feed for 5 minutes
    agent.like_x_posts(duration=300)
    
    # Follow specific users
    agent.follow_x_users(["https://x.com/jacob_somer_"], duration=300)
finally:
    agent.close()

Using Microsoft Edge Browser

To automate actions using the Edge browser, modify the driver and profile paths:

from xagent.agent import XAgent

edge_driver_path = "/Users/<username>/edgedriver_mac64_m1/msedgedriver"
edge_profile_path = "/Users/<username>/Library/Application Support/Microsoft Edge/User Data"

agent = XAgent(
    driver_path=edge_driver_path, 
    profile_path=edge_profile_path, 
    browser="edge"
)

try:
    # Like posts on your feed for 5 minutes
    agent.like_x_posts(duration=300)
    
    # Follow specific users
    agent.follow_x_users(["https://x.com/jacob_somer_"], duration=300)
finally:
    agent.close()

XAgent Methods

__init__(self, driver_path, profile_path, x_username=None, x_password=None, browser="chrome")

Initializes the XAgent.

  • driver_path: Path to the ChromeDriver executable. Download ChromeDriver from here.
  • profile_path: Path to the user profile directory for Chrome. To find this, type "chrome://version" into your Chrome browser's address bar, and look for the "Profile Path" variable.
  • x_username (optional): Twitter (X) username for authentication.
  • x_password (optional): Twitter (X) password for authentication.
  • browser: The browser to use, either "chrome" or "edge".

like_x_posts(duration=300)

👍 Likes posts on the user's feed for the specified duration.

follow_x_users(users, duration=300)

👥 Follows the specified Twitter (X) users for the specified duration.

get_x_followers(username)

📈 Gets the followers of a specified Twitter (X) user.

get_x_following(username)

📊 Gets the users that a specified Twitter (X) user is following.

unfollow_x_users(users)

🚫 Unfollows the specified Twitter (X) users.

unfollow_x_users_alternative(user, users)

🔄 Unfollows the specified Twitter (X) users using an alternative method.

get_x_handles(query, num_handles=10)

🔍 Gets the handles of users based on a query.

Running Tests

To run the tests for this package, use the unittest framework:

python -m unittest discover tests

License

This project is licensed under the MIT License - see the LICENSE file for details.