多文件自動上傳程序.

本文內容已被 [ poiuyt ] 在 2012-12-04 13:33:12 編輯過。如有問題,請報告版主或論壇管理刪除.

This program is made to automate the process of uploading multiple files to WXC. It has been tested on Windows 7 and XP.

Installation.

  1. Download Autoit v3 and install it, and note down the installation path (the default path is C:\Program Files\AutoIt3) which will be used below
  2. Create a directory, like C:\upload.
  3. Copy this code and paste it into an editor like NOTEPAD:
  4. #include <IE.au3>
    Opt("WinTitleMatchMode",2)  ;match substring of window
    Opt("MustDeclareVars",1)
    Func FileBrowserWindow($file,$memo)
        _IENavigate($IE,"http://bbs.wenxuecity.com/legacy/upload")
        Local $Obj = _IEDocGetObj($IE)
        While _IEPropertyGet($IE, "busy") = True
            Sleep(50); wait while IE is busy
        WEnd
        $IE.Document.All.Item("memo").Value=$memo
        $IE.Document.All.Item("username").Value=$username
        $IE.Document.All.Item("password").Value=$password
        Local $postform = _IEFormGetObjByName($IE, "postform")
        Local $music = _IEFormElementGetObjByName($postform, "music")
        Local $title
        If  @OSVersion = "WIN_XP" Then
            _IEAction($music, "focus")
            ControlSend(_IEPropertyGet($IE, "hwnd"), "", "", $file)
        Else
            _IEAction($music, "focus")
            Local $hIE = _IEPropertyGet($IE, "hwnd")
            $title="Choose File to Upload"
            ControlSend($hIE, "", "", " ")
            WinWaitActive($title, "", 10);
            ControlSetText($title, "", "[CLASS:Edit; INSTANCE:1]", $file)
            ControlClick($title, "", "[CLASS:Button; INSTANCE:1]")
        EndIf
        $IE.Document.All.Item("fileupload").click
        While isobj($IE.Document.All.Item("fileupload"))
            Sleep(50)
        WEnd
    EndFunc
    _IEErrorHandlerRegister("MyErrFunc")
    Func MyErrFunc()
        Local $ErrorScriptline = $oIEErrorHandler.scriptline
        Local $ErrorNumber = $oIEErrorHandler.number
        Local $ErrorNumberHex = Hex($oIEErrorHandler.number, 8)
        Local $ErrorDescription = StringStripWS($oIEErrorHandler.description, 2)
        Local $ErrorWinDescription = StringStripWS($oIEErrorHandler.WinDescription, 2)
        Local $ErrorSource = $oIEErrorHandler.Source
        Local $ErrorHelpFile = $oIEErrorHandler.HelpFile
        Local $ErrorHelpContext = $oIEErrorHandler.HelpContext
        Local $ErrorLastDllError = $oIEErrorHandler.LastDllError
        Local $ErrorOutput = ""
        $ErrorOutput &= "--> COM Error Encountered in " & @ScriptName & @CR
        $ErrorOutput &= "----> $ErrorScriptline = " & $ErrorScriptline & @CR
        $ErrorOutput &= "----> $ErrorNumberHex = " & $ErrorNumberHex & @CR
        $ErrorOutput &= "----> $ErrorNumber = " & $ErrorNumber & @CR
        $ErrorOutput &= "----> $ErrorWinDescription = " & $ErrorWinDescription & @CR
        $ErrorOutput &= "----> $ErrorDescription = " & $ErrorDescription & @CR
        $ErrorOutput &= "----> $ErrorSource = " & $ErrorSource & @CR
        $ErrorOutput &= "----> $ErrorHelpFile = " & $ErrorHelpFile & @CR
        $ErrorOutput &= "----> $ErrorHelpContext = " & $ErrorHelpContext & @CR
        $ErrorOutput &= "----> $ErrorLastDllError = " & $ErrorLastDllError
        MsgBox(0, "COM Error", $ErrorOutput)
        SetError(1)
        Return
    EndFunc   ;==>MyErrFunc
    If  $CmdLine[0] <> 1 Then
        MsgBox(0, "Usage", "autoit3 script.txt playlist.txt")
        Exit
    EndIf
    Local $file = FileOpen($CmdLine[1], 128)
    If $file = -1 Then
        MsgBox(0, "Error", "Unable to open playlist file : "&$CmdLine[1])
        Exit
    EndIf
    Local $username, $password
    Local $IE = _IECreate()
    $IE.Visible = 1
    While 1
        Local $line = FileReadLine($file)
        If @error = -1 Then ExitLoop
        Local $array
        $array = StringRegExp($line,"^\s*password\s*=\s*(\S*)", 1)
        If  UBound($array) = 1 Then
            $password=$array[0]
        EndIf
        $array = StringRegExp($line,"^\s*username\s*=\s*(\S*)", 1)
        If  UBound($array) = 1 Then
            $username=$array[0]
        EndIf
        $array = StringRegExp($line,"^\s*(.+?)\s*[|]\s*(.*)", 1)
        If  UBound($array) = 2 Then
            If FileExists($array[0]) Then
                FileBrowserWindow($array[0],$array[1])
            Else
                MsgBox(4096, "This file does not exist : ", $array[0])
            EndIf
        EndIf
    WEnd
    FileClose($file)

    In the rare situation where you see a single line of code in NOTEPAD, then you have to use another editor like WRITE (also know as WORDPAD on Windows 7).

  5. Save the file in the directory (C:\upload) created above, naming it script.txt, making sure you choose encoding as "UNICODE".
  6. Start Windows Explorer, browse to the directory C:\upload, right click on the blank area in the right panel, then New⇒Shortcut
    Type "C:\Program Files\AutoIt3\AutoIt3.exe", then Next
    Type "upload" (without quotes), then Finish
  7. Right-click shortcut "upload" just created and choose Properties
    Change "Target" to :
    "C:\Program Files\AutoIt3\AutoIt3.exe" script.txt playlist.txt
    Change "Start in" to :
    C:\upload
  8. In C:\upload, create a sub-folder named "mp3" (without quotes) which will contain mp3 files to be uploaded.

Usage.

  1. Start NOTEPAD and then type in following lines
    username=poiuyt
    password=secret
    C:\upload\mp3\1.mp3 | 第一首歌名
    C:\upload\mp3\2.mp3 | 第二首歌名
    C:\upload\mp3\3.xml | Playlist
    ...
    username/password are those one uses to log on Wenxuecity.
    Each song line is composed of the path to the mp3 file and song name separated by a pipe |. Other types of files (like .xml) can be uploaded as demonstrated by the third line.
    Save the content to a file called "playlist.txt"(without quotes, in C:\upload), by MAKING SURE you choose encoding as "UNICODE".
  2. Double click shortcut "upload", which will start uploading all the mp3 in playlist.txt.

所有跟帖: 

*************收入論壇幫助“熱心網友” -yy888- 給 yy888 發送悄悄話 yy888 的博客首頁 (321 bytes) () 11/23/2012 postreply 18:55:22

回複:收入論壇幫助“熱心網友” -poiuyt- 給 poiuyt 發送悄悄話 poiuyt 的博客首頁 (111 bytes) () 11/24/2012 postreply 08:09:19

****這個程序可以用來在文學城上傳多首mp3,做專輯的童鞋可以試試 -yy888- 給 yy888 發送悄悄話 yy888 的博客首頁 (105 bytes) () 11/23/2012 postreply 19:00:14

非常欣賞你的熱心,如果你用VB重寫,生成一個可執行文件 -無情有義- 給 無情有義 發送悄悄話 (129 bytes) () 11/24/2012 postreply 14:06:20

多謝有義兄支招 :) -poiuyt- 給 poiuyt 發送悄悄話 poiuyt 的博客首頁 (213 bytes) () 11/24/2012 postreply 15:34:53

VB or Java Script 都可以做這個工作,但是使用它們的人都需要有 -無情有義- 給 無情有義 發送悄悄話 (370 bytes) () 11/24/2012 postreply 20:05:47

請您先登陸,再發跟帖!