自动发表QQ空间说说

require("gb2312toutf8")
local http = require "socket.http"
local surl = "http://www.jokeji.cn"
local function getUrl(c)
    if c:sub(1,1) == "/" then
        return surl .. c
    else 
        return surl .. "/" .. c
    end
end
-- 发表说说
local QQfabiao = socket.protect(function(con)
    function fabiao(con)
        local t = {}
        local reqt = {
            url = "http://taotao.qzone.qq.com/cgi-bin/emotion_cgi_publish_v6?g_tk=881884919",
            sink = ltn12.sink.table(t)
        }
        local b = [[code_version=1&con=]] .. con ..[[&feedversion=1&format=fs&hostuin=1246747572&
paramstr=1&pic_template=&qzreferrer=http%3A%2F%2Fuser.qzone.qq.com%2F1246747572%2Finfo
center%3Fptsig%3D6JR2IckHBsW62y*a8Yyk-D5kl2*LY57C7ekyMPUwblQ_&richtype=&richval=&specia
l_url=&subrichtype=&syn_tweet_verson=1&to_sign=0&to_tweet=0&ugc_right=1&ver=1&who=1]]
        if b then
            reqt.source = ltn12.source.string(b)
            reqt.headers = {
                ["content-length"] = string.len(b),
                ["content-type"] = "application/x-www-form-urlencoded",
                ["cookie"] = "pgv_pvid=2921257289; pt2gguin=o1246747572; 
ptcz=f19275426fb17fa422bc3db0ea1c152651d9c750dc26c80c5e96540ad52e53a6;
o_cookie=1246747572; RK=i3cumo4Hct; pgv_pvi=3924128768; p_o2_uin=1246747572; 
ptui_loginuin=1246747572; qqmusic_uin=12345678; qqmusic_key=12345678; 
qqmusic_fromtag=6; pgv_info=ssid=s5823528911; skey=@dbKiNxZAF; ptisp=ctc; 
uin=o1246747572; QZ_FE_WEBP_SUPPORT=0; cpu_performance_v8=6; __Q_w_s__QZN_TodoMsgCnt=1; 
__Q_w_s_hat_seed=1; __Q_w_s__appDataSeed=1; Loading=Yes; qzmusicplayer=qzone_player_1246747572_1455773155776; 
blabla=dynamic; zzpaneluin=; zzpanelkey=; p_skey=b78i01A*1Yq-*TEtkbR6QRPA3dIZIrjhnmmAyz8UW7g_; 
pt4_token=TZ8e*Y1mPItaWRJU4ROK62LyO5gycJyNsDHyXA-GV4A_; p_uin=o1246747572"
            }
            reqt.method = "POST"
        end
        local code, headers, status = socket.skip(1, http.trequest(reqt))
        return table.concat(t), code, headers, status    
    end
    return fabiao(con)
end)
-- 延时n秒
local function sleep(n)
    if n<=0 then return end
    local cur = os.time()
    while os.time() - cur ~= n do
    end
end 
local body,ret = http.request(getUrl("list18_1.htm"))
body = mylib.gb2312toUtf8(body)
local filter = {}
filter["/jokehtml/ym/201602142231174.htm"] = 0
filter["/jokehtml/ym/2016020308024982.htm"] = 0
function getCon(body)
    for w in string.gmatch(body, "href=\"(.-)\"") do
        if string.find(w,".*%d.htm") then 
            local body,ret = http.request(getUrl(w))
            if(body and #body>1 and not filter[w]) then
                body = mylib.gb2312toUtf8(body)
                if body:find("<P>") then
                    for w in string.gmatch(body, "<[pP]>(.-)</[pP]>") do
                        local s,_ = string.gsub(w,"<[aA].*</[aA]>","")
                        s = string.gsub(s,"<BR>","\n")
                        s = string.gsub(s,"<[spanSPAN]>.-</[spanSPAN]>","")
                        s = string.gsub(s,"%d+、","")
                        if(#s>3) then
                            s = s .. "\n\n-------- 来自小强的爬虫 --------"
                        end
                        -- print(s)
                        local b,r = QQfabiao(s)
                        sleep(60)
                    end
                else
                    getCon(body)
                end             
            end
        end
    end
end
getCon(body)

猜你喜欢

转载自www.cnblogs.com/dzqdzq/p/11084822.html