Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/21.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 Mechanize访问网站部分有困难_Ruby_Mechanize - Fatal编程技术网

使用Ruby Mechanize访问网站部分有困难

使用Ruby Mechanize访问网站部分有困难,ruby,mechanize,Ruby,Mechanize,我正在尝试访问airbnb列表上的日历数据,但迄今为止未成功。我在Ruby中使用Mechanize gem,当我尝试访问链接以访问表时,遇到以下错误: require 'mechanize' agent = Mechanize.new page1=agent.get("https://www.airbnb.com/rooms/726348") page2=agent.get("https://www.airbnb.com/rooms/calendar_tab_inner2/73944?cal_m

我正在尝试访问airbnb列表上的日历数据,但迄今为止未成功。我在Ruby中使用Mechanize gem,当我尝试访问链接以访问表时,遇到以下错误:

require 'mechanize'
agent = Mechanize.new
page1=agent.get("https://www.airbnb.com/rooms/726348")
page2=agent.get("https://www.airbnb.com/rooms/calendar_tab_inner2/73944?cal_month=11&cal_year=2013&currency=USD")
Mechanize::ResponseCodeError: 400 => Net::HTTPBadRequest for https://www.airbnb.com/rooms/calendar_tab_inner2/726348?cal_month=11&cal_year=2013&currency=USD -- unhandled response
我还尝试用以下代码单击生成表的选项卡,但这样做只是从原始url生成html

agent = Mechanize.new
page1=agent.get("https://www.airbnb.com/rooms/726348")
page2=agent.click(page1.link_with(:href => '#calendar'))

任何帮助都将不胜感激。谢谢

我发现了问题,您需要检查请求头:

page = agent.get url, nil, nil,  {'X-Requested-With' => 'XMLHttpRequest'}

您的
page2
链接对我无效。但是这一个没有
https://www.airbnb.co.uk/rooms/calendar_tab_inner2/726348?cal_month=11&cal_year=2013¤cy=GBP
不幸的是,这一切都不起作用。看起来您需要能够处理javascript的东西