ウェブサイトでscrapy + splashで使用したいluaスクリプトを作成しています。テキストを入力してボタンをクリックするスクリプトを作成したいと思います。私は自分のコードが正しく実行されるかどうかをテストするためにスプラッシュAPIを使用しています今スプラッシュAPI/luaエラー:ローカル要素のインデックスを作成しようとしています(ゼロ値)
function main(splash)
local url = splash.args.url
assert(splash:go(url))
assert(splash:wait(5))
local element = splash:select('.input_29SQWm')
assert(element:send_text("Wall Street, New York"))
assert(splash:send_keys("<Return>"))
assert(splash:wait(5))
return {
html = splash:html(),
}
end
:私は、次のコードを持っています。 「レンダリング」をクリックすると次のメッセージが表示されます。
{
"info": {
"message": "Lua error: [string \"function main(splash)\r...\"]:7: attempt to index local 'element' (a nil value)",
"type": "LUA_ERROR",
"error": "attempt to index local 'element' (a nil value)",
"source": "[string \"function main(splash)\r...\"]",
"line_number": 7
},
"error": 400,
"type": "ScriptError",
"description": "Error happened while executing Lua script"
}
「Wall Street、New York」を送信しようとすると、何らかの理由で要素がまだゼロです。なぜか分からない。
$('.input_29SQWm')
私は希望の要素を見つけました。
Q:誰かが間違っていることを知っていますか?
ありがとうございます!
'nil'値は、' document.querySelector( '。input_29SQWm') 'が結果を返しなかったことを意味します。なぜこれがスプラッシュで起こったのですが、Chromeではどうなったのですか?それは伝えにくいです。スプラッシュに要素が表示されないようなエラーがあるかもしれません。デバッグには、最初の 'splash:wait()'の直後に 'splash:html()'と 'splash:png()'を返して、その要素がページに存在することを確認します。 –