如何与Scrubyt建立“下一页”链接

时间:2008-10-03 20:56:11

标签: ruby scrubyt

我正在尝试使用Scrubyt从此页面获取详细信息http://www.nuffieldtheatre.co.uk/cn/events/event_listings.php?section=events。我已经设法从列表中获取标题和详细信息URL,但我无法使用next_page让刮刀转到下一页。我认为这是因为我没有使用正确的模式进行下一页链接。我尝试了字符串“Next Page”,我也尝试了XPath。还有其他想法吗?

代码如下:

require 'rubygems'
require 'scrubyt'

nuffield_data = Scrubyt::Extractor.define do
  fetch 'http://www.nuffieldtheatre.co.uk/cn/events/event_listings.php?section=events'

  event do
    title 'The Coast of Mayo'
    #url "href", :type => :attribute
    link_url
  end

  next_page "Next Page", :limit => 2


end

  nuffield_data.to_xml.write($stdout,1)

1 个答案:

答案 0 :(得分:2)

尝试使用略有不同的网址:

fetch 'http://www.nuffieldtheatre.co.uk/cn/events/event_listings.php'

scrubyt似乎在网址末尾有“?section = events”查询问题。

当它查找下一页时,它会尝试返回此URL:

http://www.nuffieldtheatre.co.uk/cn/events/?pageNum_rsSearch=1&totalRows_rsSearch=39&section=events

而不是:

http://www.nuffieldtheatre.co.uk/cn/events/event_listings.php?pageNum_rsSearch=1&totalRows_rsSearch=39&section=events

删除URL末尾的查询字符串似乎解决了这个问题 - 您可能希望将此文件作为错误提交。