登录

设置cookie

修改请求头

爬取帖子标题

自动发帖

发帖

# _*_ coding : utf-8 _*_
# @Time : 2023-11-22 10:33
# @Author : Kmoon_Hs
# @File : post_discussion

import  requests

header = {
    'cookie': '' #浏览器F12
}

def addDiscussion(title):
    data = {
        'callCount': '1',
        'scriptSessionId': '${scriptSessionId}190',
        'httpSessionId': 'd13baa8b1ff649e6b3c46f93f695d115',
        'c0-scriptName': 'MocForumBean',
        'c0-methodName': 'addPost',
        'c0-id': '0',
        'c0-e1': 'number:1231719713',
        'c0-e2': f'string:{title}',
        'c0-e3': 'string:',
        'c0-e4': 'number:0',
        'c0-e5': 'boolean:true',
        'c0-e6': 'number:1471228456',
        'c0-e7': 'number:-1',
        'c0-e8': 'number:1',
        'c0-param0': 'Object_Object:{forumId:reference:c0-e1,title:reference:c0-e2,content:reference:c0-e3,anonymous:reference:c0-e4,hasFollowed:reference:c0-e5,termId:reference:c0-e6,rootForumId:reference:c0-e7,type:reference:c0-e8}',
        'c0-param1': 'Array:[]',
        'batchId': '1700618195337'
    }

    response = requests.post(url='<https://www.icourse163.org/dwr/call/plaincall/MocForumBean.addPost.dwr>',
                             headers=header, data=data)
    content = response.content

    print(content)

获取讨论区主题

# _*_ coding : utf-8 _*_
# @Time : 2023-11-22 9:54
# @Author : Kmoon_Hs
# @File : get_topics

import requests
import re

data = {
    'callCount': 1,
    'scriptSessionId': '190',
    'httpSessionId': 'd13baa8b1ff649e6b3c46f93f695d115',
    'c0-scriptName': 'PostBean',
    'c0-methodName': 'getAllPostsPagination',
    'c0-id': 0,
    'c0-param0': 'number:1471228456',
    'c0-param1': 'string:1231719713',
    'c0-param2': 'number:0',
    'c0-param3': 'number:1',   #pageNum
    'c0-param4': 'number:20',  #Nums of One Page
    'c0-param5': 'boolean:false',
    'c0-param6': 'null:null',
    'batchId': '1700618194742'
}

header = {
    'cookie' : ''
}

response = requests.post('<https://www.icourse163.org/dwr/call/plaincall/PostBean.getAllPostsPagination.dwr>', data=data,headers=header)
content = response.content.decode(encoding='UTF-8').encode().decode("unicode_escape")
pattern = r'title="([^"]+)"'
matches = re.findall(pattern, content)
titles = []
for match in matches:
    titles.append(match)

if __name__ == '__main__':
    for item in titles:
        print(item)