# -*- coding:utf-8 -*-
import requests
# 登录账号
username = 'username'
password = 'password'
# 登录地址
login_url = 'http://www.example.com/login'
# 构造登录参数
data = {
'username': username,
'password': password
}
# 构造请求头
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36'
}
# 发起登录请求
response = requests.post(url=login_url, data=data, headers=headers)
# 检查是否登录成功
if response.status_code == 200:
print('登录成功')
# 请求踢楼地址
kick_url = 'http://www.example.com/kick'
# 构造踢楼参数
data = {
'floor_id': 'xxx'
}
# 发起踢楼请求
response = requests.post(url=kick_url, data=data, headers=headers)
# 检查是否踢楼成功
if response.status_code == 200:
print('踢楼成功')
以下是hostloc自动踢楼代码
import requests
from bs4 import BeautifulSoup
# 填入账号密码
username = ""
password = ""
# 登录
login_url = "https://www.hostloc.com/member.php?mod=logging&action=login&loginsubmit=yes&loginhash=L9X1e"
data = {
"username": username,
"password": password
}
session = requests.session()
session.post(login_url, data=data)
# 获取帖子链接
forum_url = "https://www.hostloc.com/forum-45-1.html"
resp = session.get(forum_url)
soup = BeautifulSoup(resp.text, "lxml")
titles = soup.find_all("a", class_="s xst")
# 访问帖子链接
for title in titles:
post_url = "https://www.hostloc.com/" + title["href"]
resp = session.get(post_url)
soup = BeautifulSoup(resp.text, "lxml")
# 找到楼层
floors = soup.find_all("div", class_="pi")
for floor in floors:
# 找到楼主
author = floor.find("div", class_="authi").find("a").text
# 如果不是楼主,则踢楼
if author != username:
# 找到楼层ID
floor_id = floor.find("a", class_="fastre")["href"].split("pid=")[1].split("&")[0]
kick_url = "https://www.hostloc.com/forum.php?mod=topicadmin&action=moderate&fid=45&moderate[]={}&handlekey=moderate&infloat=yes&nopost=yes".format(floor_id)
session.get(kick_url)