Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带有动态网站的Ruby开放URI_Ruby_Open Uri - Fatal编程技术网

带有动态网站的Ruby开放URI

带有动态网站的Ruby开放URI,ruby,open-uri,Ruby,Open Uri,我正在尝试使用OpenURI获取网站的html页面。然而,问题是网站需要几秒钟的时间才能加载正确的代码。我现在得到的是: require 'open-uri' html = open('http://hiddencode.me/dribbbucket/embed.html?key=MY_API_KEY&bucket=56024-Glassboard&delay=5000') response = html.read puts response 如果我现在运行这个,我会得到:

我正在尝试使用OpenURI获取网站的html页面。然而,问题是网站需要几秒钟的时间才能加载正确的代码。我现在得到的是:

require 'open-uri'

html = open('http://hiddencode.me/dribbbucket/embed.html?key=MY_API_KEY&bucket=56024-Glassboard&delay=5000')
response = html.read
puts response
如果我现在运行这个,我会得到:

<div id="slam-dunk">
    <div id="loading">Loading..</div>
</div>

加载。。

但是,在打开网站之前,网站需要先正确加载,以获得正确的响应。你知道如何在ruby中做到这一点吗?如果ruby不是您的专长,我也可以使用另一种语言的解决方案

例如,我最近完成了一项类似的任务。您将能够在javascript执行后查询DOM,并提取您想要的任何内容。如果你希望它是无头的,在我的情况下,我用的是无头宝石


如果您想坚持使用“openuri”,那么您必须使用类似的工具来观察javascript发出哪些ajax请求。您也可以使用许多不同的工具来实现这一点。但是在本例中,您应该在访问url之前启动httpfox。等待,直到您看到您试图抓取的信息出现,然后停止httpfox并检查每个请求,检查每个响应是否与您正在抓取的内容相关。一旦确定了正确的请求,就可以将其与开放uri一起使用。虽然是最简单的解决方案,但由于web应用程序与服务器交互和操作dom的方式各不相同,因此无法保证此解决方案。

您需要一个无头浏览器,或者可以执行JavaScript的simmering。有很多选择。你应该打开AJAX使用的URL。谢谢!当我这样做的时候,我确实最终使用了watir来完成任务。