File size: 2,325 Bytes
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
# 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/Творчество-роботов-нейросети-и-т-п.17617/'
#thread_url = 'https://waronline.org/fora/index.php?threads/%D0%A2%D0%B2%D0%BE%D1%80%D1%87%D0%B5%D1%81%D1%82%D0%B2%D0%BE-%D1%80%D0%BE%D0%B1%D0%BE%D1%82%D0%BE%D0%B2-%D0%BD%D0%B5%D0%B9%D1%80%D0%BE%D1%81%D0%B5%D1%82%D0%B8-%D0%B8-%D1%82-%D0%BF.17617/'

# 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 a message to the thread
post_data = {
    'message_html': 'Hello world!',  # Replace with your message
    'last_date': '',  # Leave empty for a new post
    'watch_thread': '1',  # Subscribe to the thread (optional)
    '_xfToken': xf_token,  # Retrieve the token from the page HTML '1676385710,1cdf871cad6915a8f95aa9ddb0e03cc9'
    '_xfRequestUri': thread_url,  # Retrieve from the page HTML
    '_xfWithData': '1',  # Required for some XenForo versions
    '_xfResponseType': 'json'  # Receive the response in JSON format
}
response = session.post(thread_url, data=post_data)

# Check if the post was successful
if not response.ok:
    print('Post failed!')
    exit()

print('Post submitted successfully.')