微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

带有 Splash 的响应表中缺少时间键

如何解决带有 Splash 的响应表中缺少时间键

上周当我运行我的代码时,Splash 响应的表中有 timings。现在我再次运行代码它突然消失了。

local entries = splash:history()
if next(entries) ~= nil then
    local last_response = entries[#entries].response

    if (type(last_response) == "table") then
        for a,b in pairs(last_response) do
            print(a)
            if (type(b) == "table") then
                for c,d in pairs(b) do
                    print('\t',c)
                    print('\t\t',d)
                end
            else
                print('\t',b)
            end
        end
    end
end

返回:

statusText
                OK
ok
                true
httpVersion
                HTTP/1.1
bodySize
                195
content
                mimeType
                        text/html
                size
                        0
redirectURL

status
                200
headers
                1
                        table: 0x2063c90
                2
                        table: 0x210a890
                3
                        table: 0x20fe780
                4
                        table: 0x2101310
                5
                        table: 0x2101d20
                6
                        table: 0x2077540
                7
                        table: 0x207bd80
                8
                        table: 0x1ec4a30
                9
                        table: 0x1e500f0
headeRSSize
                232
url
                https://www.example.com
cookies

什么可以解释 timings 的消失?

这是完整的 Splash 脚本:

function main(splash,args)
    local max_wait_time_in_seconds = 5
    local start_time = os.clock()

    local return_status
    local return_headers
    local return_timings
    local return_body_size

    assert(splash:go(args.url))

    while not splash:evaljs("document.readyState === 'complete'") do
        if (os.clock()-start_time > 10) then
            return nil
        end

        assert(splash:wait(0.05))
    end

    local entries = splash:history()
    if next(entries) ~= nil then
        local last_response = entries[#entries].response

        if (type(last_response) == "table") then
            for a,b in pairs(last_response) do
                print(a)
                if (type(b) == "table") then
                    for c,d in pairs(b) do
                        print('\t',c)
                        print('\t\t',d)
                    end
                else
                    print('\t',b)
                end
            end

            return_status = last_response.status
            return_headers = last_response.headers
            return_timings = last_response.timings
            return_body_size = last_response.bodySize
        end
    end

    return {
        html = splash:html(),headers = return_headers,timings = return_timings,http_status = return_status,body_size = return_body_size
    }
end

这是我的 SplashRequest:

yield SplashRequest(
    url = self.start_url,callback = self.parse_response,magic_response = True,endpoint = 'execute',args = {
        'lua_source': self.splash_lua_script
    }
)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。