欢迎

做什么都可以

编辑下方内容

编辑下方内容

#!/usr/bin/env python3
# coding: utf-8
# Delete all pages in a category with Wikidot unreleased API
# Author: https://github.com/lwd-temp
# Please notice, using unreleased API may violate Wikidot's Terms of Service about forbidden reverse engineering
import time
 
import lxml.html
import requests
 
# EDIT THESE SETTINGS
# Link to your Wikidot site
# Format: http://your-site.wikidot.com
site = 'PLEASE_EDIT_ME'  # Change to your site
 
# Catagory ID to be completely deleted
# In /system:recent-changes , query the category you want to delete, get the category id from DevTools -> Network -> ajax-module-connector.php -> Payload -> categoryId
category_id = 'PLEASE_EDIT_ME'  # Change to your category id
 
# Global Proxy Settings
proxies = {
    "http": "http://127.0.0.1:8080"  # Change to your proxy
}
 
# Global Cookies, get from browser or DevTools -> Network -> ajax-module-connector.php -> Cookie
# Please notice that the loggin session must be valid and the user must have the permission to delete pages
cookies = {
    'wikidot_udsession': 'PLEASE_EDIT_ME',
    'WIKIDOT_SESSION_ID': 'PLEASE_EDIT_ME',
    'wikidot_token7': 'PLEASE_EDIT_ME',
}
# END OF SETTINGS
 
# Global Headers Template, this is the default value of MS Edge
headers = {
    'Accept': '*/*',
    'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
    'Connection': 'keep-alive',
    'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
    # 'Cookie':
    'Origin': site,
    'Referer': site + '/#REPLACEME#',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 Edg/109.0.1518.70',
    'X-Requested-With': 'XMLHttpRequest',
}
 
def getDeletedCatagoryPageList():
    data = {
        'category_id': category_id,
        'moduleName': 'list/WikiCategoriesPageListModule',
        'callbackIndex': '1',
        'wikidot_token7': cookies['wikidot_token7'],
    }
 
    response = requests.post(
        site + '/ajax-module-connector.php',
        cookies=cookies,
        headers=headers,
        data=data,
        verify=False,
        proxies=proxies,
    )
 
    html = response.json()['body']
    # Get all href & rm /
    page_list = [i.split('/')[1]
                 for i in lxml.html.fromstring(html).xpath('//a/@href')]
 
    return page_list
 
def getPageId(page_name):
    response = requests.get(
        site + '/' + page_name + '/noredirect/true',
        cookies=cookies,
        headers=headers,
        verify=False,
        proxies=proxies,
    )
 
    # WIKIREQUEST.info.pageId = XXXXXXX;
    page_id = response.text.split('WIKIREQUEST.info.pageId = ')[
        1].split(';')[0].strip()
 
    return page_id
 
def deletePage(id, page_name):
    data = {
        'action': 'WikiPageAction',
        'event': 'deletePage',
        'page_id': str(id),
        'moduleName': 'Empty',
        'callbackIndex': '2',
        'wikidot_token7': cookies['wikidot_token7'],
    }
 
    headers['Referer'] = headers['Referer'].replace('#REPLACEME#', page_name)
 
    response = requests.post(
        site + '/ajax-module-connector.php',
        cookies=cookies,
        headers=headers,
        data=data,
        verify=False,
        proxies=proxies,
    )
 
    return response
 
if __name__ == "__main__":
    # Get all pages in the category
    page_list = getDeletedCatagoryPageList()
    print(page_list)
    for page_name in page_list:
        # Get page id
        page_id = getPageId(page_name)
        print(page_id)
        # Delete page
        response = deletePage(page_id, page_name)
        print(response.text)
        # Sleep 5 seconds to avoid being banned
        time.sleep(5)