-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
102 lines (58 loc) · 2.52 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
== NOTES
This is a fork of aasaf's scrapi-1.2.0 gem. The intent of the fork was to
support handling of cookies.
You may pass in your cookie string in the Scrapi.scrape options hash like
so:
scraper.scrape(url, :user_agent => 'Mosaic for Amiga/1.2',
:cookies => 'chocolate_chip=1; peanut_butter=5;' )
== ScrAPI toolkit for Ruby
A framework for writing scrapers using CSS selectors and simple
select => extract => store processing rules.
Here’s an example that scrapes auctions from eBay:
ebay_auction = Scraper.define do
process "h3.ens>a", :description=>:text,
:url=>"@href"
process "td.ebcPr>span", :price=>:text
process "div.ebPicture >a>img", :image=>"@src"
result :description, :url, :price, :image
end
ebay = Scraper.define do
array :auctions
process "table.ebItemlist tr.single",
:auctions => ebay_auction
result :auctions
end
And using the scraper:
auctions = ebay.scrape(html)
# No. of auctions found
puts auctions.size
# First auction:
auction = auctions[0]
puts auction.description
puts auction.url
To get the latest source code with regular updates:
git clone git@github.com:noahhaon/scrapi.git
== Using TIDY
By default scrAPI uses Tidy to cleanup the HTML.
You need to install the Tidy Gem for Ruby:
gem install tidy
And the Tidy binary libraries, available here:
http://tidy.sourceforge.net/
By default scrAPI looks for the Tidy DLL (Windows) or shared library (Linux) in the directory lib/tidy. That's one place to place the Tidy library.
Alternatively, just point Tidy to the library with:
Tidy.path = "...."
On Linux this would probably be:
Tidy.path = "/usr/local/lib/libtidy.so"
On OS/X this would probably be:
Tidy.path = “/usr/lib/libtidy.dylib”
For testing purposes, you can also use the built in HTML parser. It's useful for testing and getting up to grabs with scrAPI, but it doesn't deal well with broken HTML. So for testing only:
Scraper::Base.parser :html_parser
== License
Copyright (c) 2006 Assaf Arkin, under Creative Commons Attribution and/or MIT License
Developed for http://co.mments.com
Code and documention: http://labnotes.org
HTML cleanup and good hygene by Tidy, Copyright (c) 1998-2003 World Wide Web Consortium.
License at http://tidy.sourceforge.net/license.html
HTML DOM extracted from Rails, Copyright (c) 2004 David Heinemeier Hansson. Under MIT license.
HTML parser by Takahiro Maebashi and Katsuyuki Komatsu, Ruby license.
http://www.jin.gr.jp/~nahi/Ruby/html-parser/README.html