作爲我論文論文的一部分,我構建了一個「機器人」,用於抓取C語言程序的官方論壇,並搜索常見問題以發佈回覆。我必須模擬登錄才能發佈相應的回覆。登錄形式如下:使用Java登錄到vbulletin論壇
- 登錄表單 - 形式的行動= 「?login.php中做=登錄」 方法= 「郵報」 的onsubmit = 「md5hash(vb_login_password,vb_login_md5password,vb_login_md5password_utf,0)」 > script type =「text/javascript」src =「clientscript/vbulletin_md5.js?v = 385」> table cellpadding =「0」cellspacing =「3」border =「0」> tr> td class =「 smallfont」樣式= 「空白:NOWRAP;」>Όνομαχρήστη TD>
TD類= 「smallfont」 NOWRAP = 「NOWRAP」>ΑυτόματηΣύνδεση /TR> TR> TD類= 「smallfont」>Κωδικός TD> TD> /TR> /TABLE>
INPUT TYPE = 「隱藏」 名稱= 「S」 值= 「」/> INPUT TYPE = 「隱藏」名稱=「securitytoken」value =「guest」/> input type =「hidden」name =「do」value =「login」/> input type =「hidden」name =「vb_login_md5password」/> input type =隱藏」的名字=‘vb_login_md5password_utf’/> /FORM> ! - /登錄窗體 - >
我已經明白,我需要MD5哈希密碼,但我不能任何登錄。我使用POST方法,我準備內容執行以下操作:
content = "do=login&url=login.php" + "&vb_login_md5password=" + md5_pass+ "&vb_login_md5password_utf="+ md5_pass + "&s=&securitytoken=guest&vb_login_username=" + UserName + "&vb_login_password=" + PassWprd;
我再發做以下的角逐:
urlConnection = (HttpURLConnection)(new URL(targetUrl).openConnection());
// Specifying that we intend to use this connection for input
urlConnection.setDoInput(true);
// Specifying that we intend to use this connection for output
urlConnection.setDoOutput(true);
// Specifying the method of HTTP request which is POST
// throws ProtocolException
urlConnection.setRequestMethod("POST");
// Specifying the content type of our post
urlConnection.setRequestProperty("Content-Type", POST_CONTENT_TYPE);
urlConnection.setRequestProperty("Content-length",String.valueOf (content.length()));
// urlConnection.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)");
// Prepare an output stream for writing data to the HTTP connection
// throws IOException
dataOutputStream = new DataOutputStream(urlConnection.getOutputStream());
dataOutputStream.writeBytes(content);
儘管如此,我無法登錄。我相信我發送的表單有問題,但我找不到。任何幫助將不勝感激,因爲我必須在幾天內完成該計劃。
我做了你所說的,我找到了正確的表單和正確的POST登錄鏈接,最後它工作。感謝您的幫助:P – fysob 2010-07-13 16:15:23
@fysob您可以使用您的代碼發佈答案嗎?我試圖在vbulletin論壇上完成同樣的事情。 – localhost 2014-11-25 05:12:48