在 Rails 3 中使用 Scrapi.. 出现分段错误错误/中止陷阱

发布于 2024-09-25 15:23:35 字数 1127 浏览 0 评论 0原文

到目前为止我所做的..

sudo gem install scrapi

sudo gem install tidy

这不起作用,因为它没有 libtidy.dylib

所以我这样做了:

sudo port install tidy

sudo cp libtidy.dylib /Library/Ruby/Gems/1.8/gems/scrapi-1.2.0/lib/tidy/libtidy.dylib

然后我开始遵循简单的railscast: http://media.railscasts.com/videos/173_screen_scraping_with_scrapi.mov

贝茨先生完成 scrapitest.rb 的第一次保存后 ,我尝试运行此代码:

require 'rubygems'
require 'scrapi'

scraper = Scraper.define do
  process "title", :page_name => :text
  result :page_name
end

uri = URI.parse("http://www.walmart.com/search/search-ng.do?search_query=lost+season+3&ic=48_0&search_constraint=0")
p scraper.scrape(uri)

使用此代码:

ruby scrapitest.rb

它返回了此错误:

/Library/Ruby/Gems/1.8/gems/tidy-1.1.2/lib/tidy/tidybuf.rb:39: [BUG] Segmentation fault
ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]

Abort trap

完全没有想法..

What I've done so far..

sudo gem install scrapi

sudo gem install tidy

This didn't work because it didn't have the libtidy.dylib

So I did this :

sudo port install tidy

sudo cp libtidy.dylib /Library/Ruby/Gems/1.8/gems/scrapi-1.2.0/lib/tidy/libtidy.dylib

Then I started following the simple railscast at : http://media.railscasts.com/videos/173_screen_scraping_with_scrapi.mov

Right after Mr. Bates finished the first save for scrapitest.rb , I tried to run this code :

require 'rubygems'
require 'scrapi'

scraper = Scraper.define do
  process "title", :page_name => :text
  result :page_name
end

uri = URI.parse("http://www.walmart.com/search/search-ng.do?search_query=lost+season+3&ic=48_0&search_constraint=0")
p scraper.scrape(uri)

With this code :

ruby scrapitest.rb

And it returned this error :

/Library/Ruby/Gems/1.8/gems/tidy-1.1.2/lib/tidy/tidybuf.rb:39: [BUG] Segmentation fault
ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]

Abort trap

Completely out of ideas..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

满天都是小星星 2024-10-02 15:23:35

我遇到了这个问题,然后又出现了一个后续问题,其中段错误会不确定地发生。

我按照这里的步骤 - http: //rubyforge.org/tracker/index.php?func=detail&aid=10007&group_id=435&atid=1744

在 tidy-1.1.2/lib/tidy/tidylib.rb 中:

1. Add this line to the 'load' method in Tidylib:


  extern "void tidyBufInit(void*)"

2. Define a new method called 'buf_init' in Tidylib:


  # tidyBufInit, using default allocator
  #
  def buf_init(buf)
    tidyBufInit(buf)
  end

然后,在 tidy 中-1.1.2/lib/tidy/tidybuf.rb:

3. Add this line to the initialize method of Tidybuf below the malloc:


   Tidylib.buf_init(@struct)

所以看起来像这样:


  # tidyBufInit, using default allocator
  #
  def buf_init(buf)
    @struct = TidyBuffer.malloc
    Tidylib.buf_init(@struct)
  end

4. For completeness, make Brennan's change by adding the allocator field to the TidyBuffer struct so that it looks like this:


  TidyBuffer = struct [
    "TidyAllocator* allocator",
    "byte* bp",
    "uint size",
    "uint allocated",
    "uint next"
  ] 

I had this issue and then a follow-up issue where a seg fault would happen non-deterministically.

I followed the steps here - http://rubyforge.org/tracker/index.php?func=detail&aid=10007&group_id=435&atid=1744

In tidy-1.1.2/lib/tidy/tidylib.rb:

1. Add this line to the 'load' method in Tidylib:


  extern "void tidyBufInit(void*)"

2. Define a new method called 'buf_init' in Tidylib:


  # tidyBufInit, using default allocator
  #
  def buf_init(buf)
    tidyBufInit(buf)
  end

Then, in tidy-1.1.2/lib/tidy/tidybuf.rb:

3. Add this line to the initialize method of Tidybuf below the malloc:


   Tidylib.buf_init(@struct)

so that is looks like this:


  # tidyBufInit, using default allocator
  #
  def buf_init(buf)
    @struct = TidyBuffer.malloc
    Tidylib.buf_init(@struct)
  end

4. For completeness, make Brennan's change by adding the allocator field to the TidyBuffer struct so that it looks like this:


  TidyBuffer = struct [
    "TidyAllocator* allocator",
    "byte* bp",
    "uint size",
    "uint allocated",
    "uint next"
  ] 
一页 2024-10-02 15:23:35

如果您收到错误:
/opt/ruby/ruby-1.8.6/lib/ruby/gems/1.8/gems/tidy-1.1.2/lib/tidy/tidybuf.rb:40: [BUG] 分段错误

这是因为数据类型不匹配最新的 Tidy (0.99) (/usr/include/buffio.h - $Date: 2007/01/23
11:17:45 $ )

解决方案是修补 tidybuf.rb:

--- tidybuf.rb  2007-04-10 09:09:01.000000000 -0500
+++ tidybuf.rb.patched  2007-04-10 09:08:55.000000000 -0500
@@ -11,6 +11,7 @@
   # Mimic TidyBuffer.
   #
   TidyBuffer = struct [
+    "int* allocator",
     "byte* bp",
     "uint size",
     "uint allocated",    

If you're getting the error:
/opt/ruby/ruby-1.8.6/lib/ruby/gems/1.8/gems/tidy-1.1.2/lib/tidy/tidybuf.rb:40: [BUG] Segmentation fault

It's because the data types don't match up in the latest Tidy (0.99) (/usr/include/buffio.h - $Date: 2007/01/23
11:17:45 $ )

The resolution is to patch tidybuf.rb:

--- tidybuf.rb  2007-04-10 09:09:01.000000000 -0500
+++ tidybuf.rb.patched  2007-04-10 09:08:55.000000000 -0500
@@ -11,6 +11,7 @@
   # Mimic TidyBuffer.
   #
   TidyBuffer = struct [
+    "int* allocator",
     "byte* bp",
     "uint size",
     "uint allocated",    
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文