{"action":"created","issue":{"url":"https://api.github.com/repos/scrapinghub/splash/issues/389","repository_url":"https://api.github.com/repos/scrapinghub/splash","labels_url":"https://api.github.com/repos/scrapinghub/splash/issues/389/labels{/name}","comments_url":"https://api.github.com/repos/scrapinghub/splash/issues/389/comments","events_url":"https://api.github.com/repos/scrapinghub/splash/issues/389/events","html_url":"https://github.com/scrapinghub/splash/issues/389","id":136173735,"number":389,"title":"Lua while loop problem","user":{"login":"WUJJU","id":7900749,"avatar_url":"https://avatars.githubusercontent.com/u/7900749?v=3","gravatar_id":"","url":"https://api.github.com/users/WUJJU","html_url":"https://github.com/WUJJU","followers_url":"https://api.github.com/users/WUJJU/followers","following_url":"https://api.github.com/users/WUJJU/following{/other_user}","gists_url":"https://api.github.com/users/WUJJU/gists{/gist_id}","starred_url":"https://api.github.com/users/WUJJU/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WUJJU/subscriptions","organizations_url":"https://api.github.com/users/WUJJU/orgs","repos_url":"https://api.github.com/users/WUJJU/repos","events_url":"https://api.github.com/users/WUJJU/events{/privacy}","received_events_url":"https://api.github.com/users/WUJJU/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2016-02-24T20:10:29Z","updated_at":"2016-03-03T17:16:05Z","closed_at":null,"body":"**I am trying run lua code in splash. But fail and don't know how to continue. \r\nBelow is my code. Anyone know how to run while loop in splash?**\r\n\r\nimport scrapy\r\nfrom scrapy.selector import Selector\r\nfrom splashtry.items import SplashtryItem\r\n\r\nclass MySpider(scrapy.Spider):\r\n    name=\"ssplash\"\r\n    allowed_domains=[\"twitter.com\"]\r\n    start_urls = [\"https://twitter.com/ScrapingHub\",\"https://twitter.com/Jackie_Sap\"]\r\n    \r\n    \r\n\r\n    def start_requests(self):\r\n        for url in self.start_urls:\r\n            script=\"\"\"\r\n            local Splash=require(\"splash\")\r\n            function Splash:wait_for(condition)\r\n                  while not condition() do\r\n                      assert(splash:runjs(\"window.scrollTo(0,document.body.scrollHeight)\"))\r\n                      assert(self:wait(0.5))\r\n                  end\r\n            end \r\n            require(\"wait_for\")\r\n\r\n            function main(splash)\r\n                 assert(splash:go(splash.args.url)) \r\n                 splash:wait_for(function()\r\n                    return splash:evaljs(\"document.body.scrollTop == document.body.scrollHeight\")\r\n                 end)\r\n                \r\n                 return splash:html()\r\n            end\r\n            \"\"\"\r\n                 \r\n            yield scrapy.Request(url, self.parse, meta={\r\n                'splash': {\r\n                    'args':{'lua_source':script},\r\n                    'endpoint':'execute',\r\n                }\r\n            })\r\n\r\n    def parse(self, response):    \r\n        sel=Selector(response)\r\n        item=SplashtryItem()\r\n        items=[]   \r\n        item['tweets']=sel.xpath('//div[@class=\"js-tweet-text-container\"]/p/text()').extract()\r\n        item['location']=sel.xpath('//span[@class=\"ProfileHeaderCard-locationText u-dir\"]').extract()\r\n        item['birth']=sel.xpath('//span[@class=\"ProfileHeaderCard-birthdateText u-dir\"]').extract()\r\n        item['name'] = sel.xpath('//title/text()').extract() \r\n        items.append(item)\r\n        return items"},"comment":{"url":"https://api.github.com/repos/scrapinghub/splash/issues/comments/191866879","html_url":"https://github.com/scrapinghub/splash/issues/389#issuecomment-191866879","issue_url":"https://api.github.com/repos/scrapinghub/splash/issues/389","id":191866879,"user":{"login":"kmike","id":107893,"avatar_url":"https://avatars.githubusercontent.com/u/107893?v=3","gravatar_id":"","url":"https://api.github.com/users/kmike","html_url":"https://github.com/kmike","followers_url":"https://api.github.com/users/kmike/followers","following_url":"https://api.github.com/users/kmike/following{/other_user}","gists_url":"https://api.github.com/users/kmike/gists{/gist_id}","starred_url":"https://api.github.com/users/kmike/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kmike/subscriptions","organizations_url":"https://api.github.com/users/kmike/orgs","repos_url":"https://api.github.com/users/kmike/repos","events_url":"https://api.github.com/users/kmike/events{/privacy}","received_events_url":"https://api.github.com/users/kmike/received_events","type":"User","site_admin":false},"created_at":"2016-03-03T17:16:05Z","updated_at":"2016-03-03T17:16:05Z","body":"hey @WUJJU,\r\n\r\nThe log shows 'bad request'; I suggest to debug your script first in Splash UI: visit `<your-splash-url>:8050` in a browser and put your script there."}}