x-web-crawler is a Python package for automating interactions on X.
You can install x-web-crawler using pip:
pip install x-web-crawlerHere’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()Here's how to automate actions on Twitter (X) using the Chrome browser:
from xagent import XAgent driver_path = "DRIVER_PATH" profile_path = "PROFILE_PATH" 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()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()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".
👍 Likes posts on the user's feed for the specified duration.
👥 Follows the specified Twitter (X) users for the specified duration.
📈 Gets the followers of a specified Twitter (X) user.
📊 Gets the users that a specified Twitter (X) user is following.
🚫 Unfollows the specified Twitter (X) users.
🔄 Unfollows the specified Twitter (X) users using an alternative method.
🔍 Gets the handles of users based on a query.
To run the tests for this package, use the unittest framework:
python -m unittest discover testsThis project is licensed under the MIT License - see the LICENSE file for details.