线程发布脚本,invision powerboard

发布于 2024-10-11 19:36:03 字数 2166 浏览 6 评论 0原文

因此,我们在某个网站上做了两件事,即下载新文件和发布文件,它们很容易定义(而且很乏味),所以我一直在尝试编写脚本。

无论如何,我已经完成了文件下载脚本。我可以重新使用登录代码,

#Cookies
cookies = http.cookiejar.LWPCookieJar()
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cookies))
urllib.request.install_opener(opener)

#Authenticate user
print("logging in")
url = "http://someurl.com/index.php?app=core&module=global&section=login&do=process"
values = {"username" : USERNAME, 
          "password" : PASSWORD}
data = urllib.parse.urlencode(values)
req = urllib.request.Request(url, data)
urllib.request.urlopen(req)

但是要发布包含所述文件的线程,您必须附加它。从我学到的如何登录的知识中,我知道如何向其发送正确的主题标题和文本。我的问题是,要附加文件,您必须将请求发送到表单而不是页面要求。 EG 您从文件对话框中选择所需的文件,然后单击附加文件,然后上传该文件,然后完成您的线程的编写,然后提交页面。

这是相关的 html

<fieldset class='attachments'> 

<script type='text/javascript'> 
//<![CDATA[
 ipb.lang['used_space'] = "Used <strong>[used]</strong> of your <strong>[total]</strong> global upload quota (Max. single file size: <strong>256MB</strong>)";
//]]>
</script> 

<h3 class='bar'>Attachments</h3> 
<!--SKINNOTE: traditional uploader needs this. --> 
<div id='attach_error_box' class='message error' style='display:none'></div> 
<input type='file' id='nojs_attach_0_1' class='input_upload' name='FILE_UPLOAD' tabindex='1' /> 
<input type='file' id='nojs_attach_0_2' class='input_upload' name='FILE_UPLOAD' tabindex='1' /> 

<ul id='attachments'><li style='display: none'></li></ul> 
<br /> 
<span id='buttonPlaceholder'></span> 
<input type='button' id='add_files_attach_0' class='input_submit' value='Attach This File' style='display: none; clear: both' tabindex='1' /> <span class='desc' id='space_info_attach_0'>Used <strong>9.45MB</strong> of your <strong>976.56MB</strong> global upload quota (Max. single file size: <strong>256MB</strong>)</span>

我不知道如何编码,所以我正在寻找方向。

另外,顺便说一句,如果这种脚本在其他语言中可能更容易,请告诉我哪一种?我只是使用Python,因为我知道它。

多谢。

So there's two things that we do on a certain site, which is download new files and post files, and they're easily definable (and tedious), so I've been trying to script it.

So anyways, I have the file downloading script done. I'm able to re use the login code

#Cookies
cookies = http.cookiejar.LWPCookieJar()
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cookies))
urllib.request.install_opener(opener)

#Authenticate user
print("logging in")
url = "http://someurl.com/index.php?app=core&module=global§ion=login&do=process"
values = {"username" : USERNAME, 
          "password" : PASSWORD}
data = urllib.parse.urlencode(values)
req = urllib.request.Request(url, data)
urllib.request.urlopen(req)

But to post a thread with said file you have to attach it. I know how to send it the proper title and text for the thread from what I learned on how to log in. My problem is that to attach files you have to send a request to a form not a page request.
E.G. You select what file you want from file dialog and then click attach files, which it then uploads, you then finish writing up you're thread and THEN submit page.

Here's relevant html

<fieldset class='attachments'> 

<script type='text/javascript'> 
//<![CDATA[
 ipb.lang['used_space'] = "Used <strong>[used]</strong> of your <strong>[total]</strong> global upload quota (Max. single file size: <strong>256MB</strong>)";
//]]>
</script> 

<h3 class='bar'>Attachments</h3> 
<!--SKINNOTE: traditional uploader needs this. --> 
<div id='attach_error_box' class='message error' style='display:none'></div> 
<input type='file' id='nojs_attach_0_1' class='input_upload' name='FILE_UPLOAD' tabindex='1' /> 
<input type='file' id='nojs_attach_0_2' class='input_upload' name='FILE_UPLOAD' tabindex='1' /> 

<ul id='attachments'><li style='display: none'></li></ul> 
<br /> 
<span id='buttonPlaceholder'></span> 
<input type='button' id='add_files_attach_0' class='input_submit' value='Attach This File' style='display: none; clear: both' tabindex='1' /> <span class='desc' id='space_info_attach_0'>Used <strong>9.45MB</strong> of your <strong>976.56MB</strong> global upload quota (Max. single file size: <strong>256MB</strong>)</span>

I have no idea how to code this, so I'm looking for direction.

Also on a sidenote if this sorta script might've been easier in other languages tell me which? I only used python because I knew it.

Thanks a lot.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文