Feeds:
文章
留言

Archive for 三月 18th, 2008

FreeGrab 下載模組 ITPUB 0.0.2

今天終於修正能夠下載電子書 ^^ ~ 不然一堆分割檔,可是會瘋掉…. 有需要的自己下載

MODULE_NAME = "ITPub"
MODULE_VERSION = "0.0.2"
MODULE_REQUIRE_VERSION = "1.2.3.3"
MODULE_AUTHOR = "cwchiu@hotmail.com"
MODULE_LAST_UPDATE = "2008/03/19"

————————————————————————-
–main
————————————————————————-
function login(url)
    local username, passwd = GetUsername(), GetPassword()
    if not username or not passwd then
        UpdateLog(‘未輸入帳密’)
        return false
    end

    GetHtml(‘http://sso.itpub.net/Login?return_url=’..url)
    Compile("(.*)");
    local _, html = What()
    –UpdateLog(html)

    GetHtml(‘http://sso.itpub.net/Token’);
    Compile("(.*)");
    local _, token = What()
    –UpdateLog(token)

    AddFormField("login_name", username)
    AddFormField("password", passwd)
    AddFormField("furmcookie", ‘365’)
    AddFormField("ts", token)
    AddFormField("cookie_flag", "")
    AddFormField("return_url", url)
    SetReferer(url)
    PostForm(‘http://sso.itpub.net/Login’)
    Compile("(.*)");
    local _, html = What()
    –UpdateLog(html);
    local token, aid = string.match(html, ‘sso_token=([0-9a-z]*)&aid=(%d+)’) ;           
    local new_url = ‘http://www.itpub.net/attachment.php?sso_token=’ .. token .. ‘&aid=’..aid;
    GetHtml(new_url)
    Compile("(.*)");
    local _, html = What()   
    –UpdateLog(‘after log: ‘ .. html);
    return new_url
end

function dumpHtml()
    GetHtml()
    Compile("(.*)");
    local _, html = What()

    UpdateLog(html)
end

function Download()   
    local url = GetUrl()
    GetHtml(url);
    Compile("(.*)");
    local _, html = What()   
    –UpdateLog(html);

    — 尚未登入
    if string.find(html, "http://sso.itpub.net/Login?return_url=") == nil then
        –UpdateLog(‘no login’)
        if login(url) == false then
            return false
        end
    end

    math.randomseed( os.time() )
    if url:find( "itpub%.net/attachment%.php" ) then                   
        local count = 0;
        local code = “;       

        GetHtml()
        if not Compile("www%.itpub%.net/authimg%.php") then return false end
        GetCaptcha(‘http://www.itpub.net/authimg.php’)
        code = PromptCaptcha(40)
        AddFormField("checkcode",code)
        SetReferer(url)
        PostForm(url)

        UpdateLog( ‘Url: ‘ .. GetUrl() )
        local aid = url:sub(url:len()-5,url:len())   
—            UpdateLog( ‘download=>’ .. ‘http://www.itpub.net/attachment.php?aid=’..aid..’&checkcode=’..code..’&downnow=1′ )
        SetReferer(url)
        if GetFile(‘http://www.itpub.net/attachment.php?aid=’..aid..’&checkcode=’..code..’&downnow=1′)                then
            return true
        end

    else
        UpdateLog("網址有誤")
    end   
    return false
end

相關連結
[1] Chui-Wen Chiu, "使用FreeGrab 抓ITPub 的電子書"

Read Full Post »