<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>posting Archives - CNERIS</title>
	<atom:link href="https://cneris.com/zh/tag/posting-zh/feed/" rel="self" type="application/rss+xml" />
	<link>https://cneris.com/zh/tag/posting-zh/</link>
	<description></description>
	<lastBuildDate>Sat, 28 Sep 2024 16:01:43 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.1</generator>
	<item>
		<title>Discuz 自动登录和发帖回帖的Python脚本</title>
		<link>https://cneris.com/zh/discuz-%e8%87%aa%e5%8a%a8%e7%99%bb%e5%bd%95%e5%92%8c%e5%8f%91%e5%b8%96%e5%9b%9e%e5%b8%96%e7%9a%84python%e8%84%9a%e6%9c%ac/</link>
					<comments>https://cneris.com/zh/discuz-%e8%87%aa%e5%8a%a8%e7%99%bb%e5%bd%95%e5%92%8c%e5%8f%91%e5%b8%96%e5%9b%9e%e5%b8%96%e7%9a%84python%e8%84%9a%e6%9c%ac/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sat, 28 Sep 2024 15:48:15 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[系统管理]]></category>
		<category><![CDATA[脚本]]></category>
		<category><![CDATA[discuz]]></category>
		<category><![CDATA[logging]]></category>
		<category><![CDATA[posting]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[scripting]]></category>
		<guid isPermaLink="false">https://cneris.com/?p=2261</guid>

					<description><![CDATA[<p>#!/usr/bin/python3 # -*- coding: utf-8 -*- import logging import re import requests class AutoDiscuz: LOGIN_URL = “/member.php?mod=logging&amp;action=login&amp;loginsubmit=yes” LOGIN_POST = {“username”: “”, “password”: “”} def __init__(self, forum_url, user_name, password): “””初始化论坛 url、用户名、密码和代理服务器.””” self.forum_url = forum_url self.user_name = user_name self.password = password self.formhash = None self.is_login = False self.session = requests.Session() logging.basicConfig(level=logging.INFO, format=”[%(levelname)1.1s %(asctime)s] %(message)s”) def login(self): “””登录论坛.””” [...]</p>
<p>The post <a href="https://cneris.com/zh/discuz-%e8%87%aa%e5%8a%a8%e7%99%bb%e5%bd%95%e5%92%8c%e5%8f%91%e5%b8%96%e5%9b%9e%e5%b8%96%e7%9a%84python%e8%84%9a%e6%9c%ac/">Discuz 自动登录和发帖回帖的Python脚本</a> appeared first on <a href="https://cneris.com/zh">CNERIS</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>#!/usr/bin/python3<br />
# -*- coding: utf-8 -*-<span id="more-2261"></span></p>
<p>import logging<br />
import re</p>
<p>import requests</p>
<p>class AutoDiscuz:<br />
LOGIN_URL = &#8220;/member.php?mod=logging&amp;action=login&amp;loginsubmit=yes&#8221;<br />
LOGIN_POST = {&#8220;username&#8221;: &#8220;&#8221;, &#8220;password&#8221;: &#8220;&#8221;}</p>
<p>def __init__(self, forum_url, user_name, password):<br />
&#8220;&#8221;&#8221;初始化论坛 url、用户名、密码和代理服务器.&#8221;&#8221;&#8221;<br />
self.forum_url = forum_url<br />
self.user_name = user_name<br />
self.password = password<br />
self.formhash = None<br />
self.is_login = False<br />
self.session = requests.Session()<br />
logging.basicConfig(level=logging.INFO,<br />
format=&#8221;[%(levelname)1.1s %(asctime)s] %(message)s&#8221;)</p>
<p>def login(self):<br />
&#8220;&#8221;&#8221;登录论坛.&#8221;&#8221;&#8221;<br />
url = self.forum_url + AutoDiscuz.LOGIN_URL<br />
AutoDiscuz.LOGIN_POST[&#8220;username&#8221;] = self.user_name<br />
AutoDiscuz.LOGIN_POST[&#8220;password&#8221;] = self.password<br />
req = self.session.post(url, data=AutoDiscuz.LOGIN_POST)<br />
if self.user_name in req.text:<br />
self.is_login = True<br />
if self.get_formhash():<br />
logging.info(&#8220;Login success!&#8221;)<br />
return<br />
logging.error(&#8220;Login faild!&#8221;)</p>
<p>def get_formhash(self):<br />
&#8220;&#8221;&#8221;获取 formhash.&#8221;&#8221;&#8221;<br />
req = self.session.get(self.forum_url)<br />
rows = re.findall(<br />
r&#8221;&lt;input type=\&#8221;hidden\&#8221; name=\&#8221;formhash\&#8221; value=\&#8221;(.*?)\&#8221; /&gt;&#8221;, req.text)<br />
if len(rows) != 0:<br />
self.formhash = rows[0]<br />
logging.info(&#8220;Formhash is: &#8221; + self.formhash)<br />
return True<br />
else:<br />
logging.error(&#8220;None formhash!&#8221;)<br />
return False</p>
<p>def reply(self, tid, subject=&#8221;&#8221;, msg=&#8221;6666666666666666666&#8243;):<br />
&#8220;&#8221;&#8221;回帖.&#8221;&#8221;&#8221;<br />
url = self.forum_url + \<br />
&#8220;/forum.php?mod=post&amp;action=reply&amp;replysubmit=yes&amp;inajax=1&amp;tid=&#8221; + \<br />
str(tid)<br />
post_data = {&#8220;formhash&#8221;: self.formhash,<br />
&#8220;message&#8221;: msg, &#8220;subject&#8221;: subject}<br />
content = self.session.post(url, post_data).text<br />
if &#8220;发布成功&#8221; in content:<br />
logging.info(&#8220;Tid: &#8221; + str(tid) + &#8221; reply success!&#8221;)<br />
return True<br />
else:<br />
logging.error(&#8220;Tid: &#8221; + str(tid) + &#8221; reply faild!&#8221;)<br />
return False</p>
<p>def main():<br />
auto_discuz = AutoDiscuz(&#8220;http://url&#8221;, &#8220;account&#8221;, &#8220;password&#8221;)<br />
auto_discuz.login()<br />
if auto_discuz.is_login:<br />
auto_discuz.reply(tid=1000)</p>
<p>if __name__ == &#8220;__main__&#8221;:<br />
main()</p>
<p>The post <a href="https://cneris.com/zh/discuz-%e8%87%aa%e5%8a%a8%e7%99%bb%e5%bd%95%e5%92%8c%e5%8f%91%e5%b8%96%e5%9b%9e%e5%b8%96%e7%9a%84python%e8%84%9a%e6%9c%ac/">Discuz 自动登录和发帖回帖的Python脚本</a> appeared first on <a href="https://cneris.com/zh">CNERIS</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://cneris.com/zh/discuz-%e8%87%aa%e5%8a%a8%e7%99%bb%e5%bd%95%e5%92%8c%e5%8f%91%e5%b8%96%e5%9b%9e%e5%b8%96%e7%9a%84python%e8%84%9a%e6%9c%ac/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
