Step 1: Set Up Your Environment
pip install requests
Now, let's create a simple bot that follows a user on social media.
import requests
# Replace with your target user's username
username = "target_user"
# Generate a random password (this should be replaced with a real one)
password = "random_password123"
# Set up the request headers
headers = {
"Authorization": f"Basic {base64.b64encode(f'{username}:{password}'.encode()).decode()}"
}
# Make the request
response = requests.get(f"/user/{username}", headers=headers)
# Check if the request was successful
if response.status_code == 200:
print("Follow request sent successfully!")
else:
print(f"Failed to follow {username}. Status code: {response.status_code}")
You've now created a basic follow bot in Python! This example uses the `requests` library to make HTTP requests to an API. In a real-world scenario, you would need to handle authentication, error handling, and more advanced features like rate limiting and cookie management.