Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

select not working #557

Closed
novoxd opened this issue Jan 17, 2017 · 6 comments
Closed

select not working #557

novoxd opened this issue Jan 17, 2017 · 6 comments

Comments

@novoxd
Copy link

novoxd commented Jan 17, 2017

My code:

function main(splash)
  assert(splash:go("http://google.com"))
  assert(splash:wait(0.5))
  return {
    a = splash:select("div"), 
    html = splash:html(),
    png = splash:png(),
    har = splash:har(),
  }
end

I get:

HTTP Error 400 (Bad Request)

Type: ScriptError -> LUA_ERROR

Error happened while executing Lua script

Lua error: [string "function main(splash)
..."]:5: attempt to call method 'select' (a nil value)

I used splash 2.3,2.2, master. Am I doing something wrong?

@kmike
Copy link
Member

kmike commented Jan 17, 2017

attempt to call method 'select' (a nil value) this should happen with Splash 2.2, but not in Spash 2.3 - the feature is new in Splash 2.3. Could you please check that the docker image is up to date?

@novoxd
Copy link
Author

novoxd commented Jan 17, 2017

I use scrapinghub/splash:latest it should be 2.3, and it has 2.3 in web interface. Tested in scrapinghub/splash:2.3 the same thing.

@kmike
Copy link
Member

kmike commented Jan 17, 2017

For me Splash 2.3 returns the following error:

{
    "description": "Error happened while executing Lua script",
    "error": 400,
    "type": "ScriptError",
    "info": {
        "type": "BAD_MAIN_ERROR",
        "message": "'main' returned bad result. Lua function objects are not allowed."
    }
}

-- this happens because splash:select() returns a Lua object, and there is no default way to serialize it to JSON. You may want to return e.g. splash:select("div").node.outerHTML instead.

Hm, maybe .node.outerHTML is a good default for serializing splash:select results, and we should add it to Splash.

@kmike
Copy link
Member

kmike commented Jan 27, 2017

@novoxudonoser have you got it working? Can I close the ticket?

@ghost
Copy link

ghost commented May 30, 2017

@kmike I came across a similar scenario and this "splash:select("div").node.outerHTML" works !

Thanks

@kmike
Copy link
Member

kmike commented Jul 6, 2017

Closing it in favor of #564.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants