爬虫:scrapy+splash 记录一次靠运气解决的问题

Lua脚本:URL:https://sustainabledevelopment.un.org/globalsdreport/2019#media

function main(splash, args)
    splash.resource_timeout = 90
    splash.images_enabled = false
    assert(splash:go(args.url))
    return {html=splash:html(),
    png=splash:png(),
     url=splash:url()
     }
end

在splash窗口运行,得到以下error:

HTTP Error 400 (Bad Request)

Type: ScriptError -> LUA_ERROR

Error happened while executing Lua script

Lua error: [string "function main(splash, args) ..."]:4: network1

{
    "error": 400,
    "type": "ScriptError",
    "description": "Error happened while executing Lua script",
    "info": {
        "source": "[string \"function main(splash, args)\r...\"]",
        "line_number": 4,
        "error": "network1",
        "type": "LUA_ERROR",
        "message": "Lua error: [string \"function main(splash, args)\r...\"]:4: network1"
    }
}

看了很多帖子,没找到解决方法,最后通过这个issue找到了灵感,Webkit error 的问题可以参考这个

assert()删除后,成功把问题解决。

改后的脚本是这样的:

function main(splash, args)
    splash.resource_timeout = 90
    splash.images_enabled = false
    splash:go(args.url)
    return {html=splash:html(),
    png=splash:png(),
     url=splash:url()
     }
end

解决原因:目前还不知道为什么,看400 networkerror1似乎是拒绝连接,但是不知道为什么去掉assert又可以了。留后面找到原因再解释。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值