猫史档案馆


论坛管喵,来封我号啊

用户:我叫以赏我叫以赏查看:41 回复:57 评论:41 创建时间:2020-05-31T20:43:36


本文章没有迎战,仅供参考,此文章为我的上文章重投版

对于月休党来说,回家的两天实在是搞不出什么大事情,在家里闲的很,不知我在整理我的收藏夹以及网盘文件的时候,我突然想起来,不是还有一个“编程喵坛”吗?那么编程猫主打的是Python,论坛的防护机制做的也不是很好,那我用Python爬虫去爬取论坛的网页数据应该是情有可原的吧?

center_image

随意打开一个帖子开始抓包,我先拿爬取编程喵坛的帖子数。

center_image

不错这句是获取帖子信息的请求,分析接口,使用GET方式,加上帖子ID就可以获取帖子的信息了。

center_image

当没有此帖子的时候就会返回404。

center_image

那么编程猫最早的帖子是什么呢?

center_image

由图可知,编程猫最早的帖子ID为54号。网址:

https://shequ.codemao.cn/community/54

center_image

找一个最近的帖子,

center_image

center_image

center_image

出现的“断崖层”,看来截止目前为止帖子数最多到304265。

我们来做一个新帖自动回复,找一个自己的帖子

center_image

center_image

测试一下,

center_image

这个就不可以简单的调用了,总之通过以上的调用方法可以正常发送一条评论,现在只要循环遍历每一个文章就行了。

center_image

开始!

center_image

哦,这个机制是防止狂刷,那么我们等待5秒。

center_image

center_image

center_image

center_image

我可不想被封号,那就到这里吧。

现在来做做自动点赞。

同样的抓包,

center_image

中间的数字应该就是评论ID了,与文章不同,

center_image

center_image

找了半天终于找到了,现在开始写代码。。。。

center_image

center_image

center_image

center_image

结果是第一层全点赞了,若要把回评论需要进一步分析,我本来就图个乐何为呢?

 

(下期 编程猫刷浏览量)

编程喵坛还有一个特性,每当评论时你的文章总会置顶,知道怎么利用了吗?


回复

上一页1 页 / 共 2下一页
蒟蒻OIer1048576蒟蒻OIer1048576

import requests
from json import dumps, loads
from bs4 import BeautifulSoup


class codemaoAPI(object):
    def __init__(self, identity, password,
                 UA='Mozilla/5.0 (Windows NT 10.0; ) AppleWebKit/537.36 (KH喵L, like Gecko) Chrome/81.0.4044.138 Safari/537.36',
                 debug=False):
        self.debug = debug
        self.ses = requests.session()
        self.headers = {"Content-Type": "application/json", "User-Agent": UA}
        self.log('getting pid...')
        soup = BeautifulSoup(requests.get('https://shequ.codemao.cn', headers = self.headers).text, 'html.parser')
        pid = loads(soup.find_all("script")[0].string.split("=")[1])['pid']
        self.log('Successfully get pid;pid=' + pid)
        self.log('loginning...')
        a = self.ses.post('https://api.codemao.cn/tiger/v3/web/accounts/login', headers = self.headers,
                          data = dumps({"identity": identity, "password": password, "pid": pid}))
        if a.status_code == 200:
            self.log("Successfully login to codemao.cn")
        else:
            self.log('End of login to codemao.cn;response', a.status_code)

    def log(self, *msg):
        if self.debug:
            print(*msg)

    def send_post(self, board, title, message):
        self.log('posting...')
        a = self.ses.post(f'https://api.codemao.cn/web/forums/boards/{board}/posts', headers = self.headers,
                          data = dumps({'title': title, 'content': message}))
        self.log('End.response', a.status_code)

    def replies(self, postID, message):
        self.log('replieing...')
        a = self.ses.post(f'https://api.codemao.cn/web/forums/posts/{postID}/replies', headers = self.headers,
                          data = dumps({'content': message}))
        self.log('End.response', a.status_code)

    def __delete_work(self, workID):  # BUG
        self.log('deleting...')
        a = self.ses.delete(f'https://api.codemao.cn/tiger/work/{workID}/temporarily', headers = self.headers)
        self.log('End.response', a.status_code)

    def __recove_work(self, workID):  # BUG
        self.log('recoving...')
        a = self.ses.patch(f'https://api.codemao.cn/tiger/work/{workID}/recover', headers = self.headers)
        self.log('End.response', a.status_code)

    def __permanent_work(self, workID):  # BUG
        self.log('permanenting...')
        a = self.ses.delete(f'https://api.codemao.cn/tiger/work/{workID}/permanently', headers = self.headers)
        self.log('End.response', a.status_code)

    def delete_all_work(self):
        self.log('All work are permanenting...')
        a = self.ses.delete('https://api.codemao.cn/tiger/work/user/works/permanently', headers = self.headers)
        self.log('End.response', a.status_code)

    def send_post_to_work_shop(self, work_shop_ID, message):
        self.log('posting...')
        a = self.ses.post(f'https://api.codemao.cn/web/discussions/{work_shop_ID}/comment', headers = self.headers,
                          data = dumps({"content": message, "rich_content": message, "source": "WORK_SHOP"}))
        self.log('End.response', a.status_code)

    def top_replies(self, repliesID):
        self.log('On top...')
        a = self.ses.put(f'https://api.codemao.cn/web/forums/replies/{repliesID}/top', headers = self.headers,
                         data = r'{}')
        self.log('End.response', a.status_code)

    def untop_replies(self, repliesID):
        self.log('Untop...')
        a = self.ses.delete(f'https://api.codemao.cn/web/forums/replies/{repliesID}/top', headers = self.headers)
        self.log('End.response', a.status_code)

    def like_replies(self, repliesID):
        self.log('liking...')
        self.ses.put(f'https://api.codemao.cn/web/forums/comments/{repliesID}/liked?source=REPLY',
                     headers = self.headers, data = r'{}')
        self.log('End.response', a.status_code)

    def unlike_replies(self, repliesID):
        self.log('Unliking...')
        self.ses.delete(f'https://api.codemao.cn/web/forums/comments/{repliesID}/liked?source=REPLY',
                        headers = self.headers)

点赞0


评论


蒟蒻OIer1048576蒟蒻OIer1048576

Click me

点赞0


评论


ZCH幻影深渊ZCH幻影深渊

代码。。。

点赞0


评论


蒟蒻OIer1048576蒟蒻OIer1048576

测试

点赞0


评论


老白篮老白篮

震惊!竟然有人沉迷于爬虫无法自拔emotion_doge

点赞0


评论


北战南钦北战南钦

还是非常nb的

点赞0


评论


你是用的sublime text吗?

点赞0


评论


我叫zzt我叫zzt

emotion_编程猫_紧张

点赞0


评论


蒟蒻OIer1048576蒟蒻OIer1048576

我是3.7的PyCharm

点赞0


评论


不起眼的账号不起眼的账号

为什么你的是中文

点赞0


评论


wrmdcxywrmdcxy

咳咳,who不会?

点赞0


评论


Weeb_ETOWeeb_ETO

emotion_喵

点赞0


评论


wrmdcxywrmdcxy

公布我的超高速刷浏览工具代码嗷:

import aiohttp,asyncio
from threading import Thread
times=1
headers={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; ) AppleWebKit/537.36 (KHT"+"ML, like Gecko) Chrome/81.0.4044.92 Safari/537.36"}
async def visit(pid):
	global times
	for x in range(5):
		async with aiohttp.ClientSession() as session:
			async with session.get("https://api.codemao.cn/web/forums/posts/"+pid+"/details") as resp:
				print(times,":visit ",pid,"\tstatus ",resp.status,sep="")
				times+=1
def start(pid):
	new_loop = asyncio.new_event_loop()
	asyncio.set_event_loop(new_loop)
	loop=asyncio.get_event_loop()
	loop.run_until_complete(asyncio.gather(visit(pid),visit(pid),visit(pid),visit(pid),visit(pid),visit(pid),visit(pid),visit(pid),visit(pid),visit(pid),visit(pid),visit(pid),visit(pid),visit(pid),visit(pid),visit(pid),visit(pid),visit(pid),visit(pid),visit(pid),visit(pid),visit(pid),visit(pid),visit(pid),visit(pid),visit(pid),visit(pid),visit(pid),visit(pid),visit(pid)))


def themain_(pid):
	for x in range(5):
		threads=[Thread(target=start,args=(pid,)) for x in range(5)]
		for t in threads:
			t.setDaemon(True)
			t.start()
		for t in threads:
			t.join()

def main_(pid):
	for x in range(5):
		threads=[Thread(target=themain_,args=(pid,)) for x in range(5)]
		for t in threads:
			t.setDaemon(True)
			t.start()
		for t in threads:
			t.join()

main_(帖子ID)

点赞0


评论


汪宰牛奶汪宰牛奶

emotion_doge

点赞0


评论


Jason12345Jason12345

一脸懵逼

点赞0


评论


不起眼的账号不起眼的账号

等官方你就完蛋了

点赞0


评论


嗯哼君 渠源嗯哼君 渠源

标题有点危险emotion_doge

点赞1


评论


Mellin_AmpMellin_Amp

爷居然上镜了emotion_doge

点赞0


评论


蒟蒻OIer1048576蒟蒻OIer1048576

GUIMaker文档 menu GUIMaker | 文档 GuiMaker介绍 GuiMaker的GUI类 GuiMaker介绍 star fork

guimaker由1048576,未入门的程序员和Toby共同开发,是一个基于tkinter的简易、轻量级的Python gui。使用它,您可以轻松的写出一个GUI程序。

GuiMaker的GUI类

"

点赞0


评论


蒟蒻OIer1048576蒟蒻OIer1048576

这是我写的图形化自动回复机

v i p

点赞0


评论


蒟蒻OIer1048576蒟蒻OIer1048576

点赞0


评论


Mikasa_Mikasa_

emotion_dogeemotion_喵喵

点赞0


评论


布偶猫是puppet布偶猫是puppet

妙啊~

点赞0


评论


ZCH无聊喵ZCH无聊喵

Python爬虫咋下载?

点赞0


评论


我叫以赏我叫以赏

如果大家要模仿的话,请不要破坏编程猫论坛规则哦

点赞2


评论


SCS_user_eeomGbEeAfSCS_user_eeomGbEeAf

emotion_喵喵

点赞0


评论


传闻中的九黎初璃传闻中的九黎初璃

提倡白帽友好交流!拒绝黑客行为,作者的置顶评论很好哇!

点赞0


评论


diaowinnerdiaowinner

我可以转载您的API吗……emotion_兔子

点赞0


评论


北酱北酱

nb

点赞0


评论


一个小糯米团子一个小糯米团子

emotion_编程猫_嗨起来

点赞0


评论