ピリオドをエスケープする正しい方法がわかりませんsplash:select
特定の要素を待機するためにluaを使用しているscrapyのスプラッシュリクエストがあります。この要素は、ID にピリオドを含む ID です。ピリオドを正しくエスケープできないようです。シングルとダブルの両方のバックスラッシュ (\
と\\
)を試しました
lua_script = '''
function main(splash)
splash:set_user_agent(splash.args.ua)
assert(splash:go(splash.args.url))
while not splash:select('div#some.id.here') do
splash:wait(0.1)
end
return {html=splash:html()}
end
'''
期待される結果は、要求されたページから完全に読み込まれた html です
実際の結果は次のとおりです。
WARNING: Bad request to Splash: {'description': 'Error happened while executing Lua script', 'error': 400, 'type': 'ScriptError', 'info': {'error': "invalid escape sequence near '\\.'", 'source': '[string "..."]', 'message': '[string "..."]:5: invalid escape sequence near \'\\.\'', 'line_number': 5, 'type': 'LUA_INIT_ERROR'}}
\
またはを使用する場合\\
そのような文字列をエスケープしようとするとsplash:select
:
splash:select(\'div#some.id.here\')
コードは継続的に実行されます (これは正しい方向への一歩だと思いますが、この段階ではコードは正しく実行されると思いますが、ピリオドを含む ID を持つ div ではなく、マルチクラスの div を見つけようとしています)