|
|
|
|
|
import requests |
|
from bs4 import BeautifulSoup |
|
|
|
|
|
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" |
|
|
|
|
|
username = 'WarBot' |
|
password = 'naP2tion' |
|
|
|
|
|
session = requests.Session() |
|
|
|
|
|
login_page_response = session.get(login_url) |
|
soup = BeautifulSoup(login_page_response.text, 'html.parser') |
|
csrf_token = soup.find('input', {'name': '_xfToken'})['value'] |
|
|
|
|
|
login_data = { |
|
'login': username, |
|
'password': password, |
|
'remember': '1', |
|
'_xfRedirect': thread_url, |
|
'_xfToken': csrf_token |
|
} |
|
response = session.post(login_url, data=login_data) |
|
|
|
|
|
if 'Invalid login' in response.text: |
|
print('Login failed!') |
|
exit() |
|
|
|
|
|
response = session.get(thread_url) |
|
|
|
|
|
soup = BeautifulSoup(response.text, 'html.parser') |
|
|
|
|
|
xf_token = soup.find('input', {'name': '_xfToken'}).get('value') |
|
|
|
post_url = "https://waronline.org/fora/index.php?threads/warbot-playground.17636/add-reply" |
|
|
|
|
|
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) |
|
|
|
|
|
if not response.ok: |
|
print('Post failed!') |
|
exit() |
|
|
|
print('Post submitted successfully.') |