新しいファイルのダウンロードとファイルの投稿です。これらは簡単に定義できる (そして面倒な) ので、スクリプトを作成しようとしています。
とにかく、ファイルのダウンロードスクリプトを完了しました。ログインコードを再利用できます
#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)
ただし、上記のファイルを含むスレッドを投稿するには、添付する必要があります。ログイン方法で学んだことから、スレッドの適切なタイトルとテキストを送信する方法を知っています。私の問題は、ファイルを添付するには、ページ要求ではなくフォームに要求を送信する必要があることです。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のみを使用しました。
どうもありがとう。