File size: 1,869 Bytes
dd2dd36 3152d9e dd2dd36 3152d9e dd2dd36 3152d9e dd2dd36 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# This is an automation of Bot to post to a specific thread in the forum.
import requests
from bs4 import BeautifulSoup
# Define the login URL and the thread URL
login_url = 'https://waronline.org/fora/index.php?login/login'
thread_url = 'https://waronline.org/fora/index.php?threads/warbot-playground.17636/'
message = "Hello World"
# Define the login credentials
username = 'WarBot'
password = 'naP2tion'
# Start a session to persist the login cookie across requests
session = requests.Session()
# Retrieve the login page HTML to get the CSRF token
login_page_response = session.get(login_url)
soup = BeautifulSoup(login_page_response.text, 'html.parser')
csrf_token = soup.find('input', {'name': '_xfToken'})['value']
# Login to the website
login_data = {
'login': username,
'password': password,
'remember': '1',
'_xfRedirect': thread_url,
'_xfToken': csrf_token
}
response = session.post(login_url, data=login_data)
# Check if the login was successful
if 'Invalid login' in response.text:
print('Login failed!')
exit()
# Retrieve the thread page HTML
response = session.get(thread_url)
# Parse the HTML with BeautifulSoup
soup = BeautifulSoup(response.text, 'html.parser')
# Extract the _xfToken value from the hidden form field
xf_token = soup.find('input', {'name': '_xfToken'}).get('value')
post_url = "https://waronline.org/fora/index.php?threads/warbot-playground.17636/add-reply"
# Construct the message data for the POST request
message_data = {
'_xfToken': xf_token,
'message': message,
'attachment_hash': '',
'last_date': '',
'_xfRequestUri': post_url,
'_xfWithData': '1',
'_xfResponseType': 'json'
}
response = session.post(post_url, data=message_data)
# Check if the post was successful
if not response.ok:
print('Post failed!')
exit()
print('Post submitted successfully.') |