shokai / Collective Intelligence study
translate from Python to Ruby
Clone this repository (size: 10.9 MB): HTTPS / SSH
$ hg clone http://bitbucket.org/shokai/collective-intelligence-study/
| commit 53: | 3038fec48571 |
| parent 52: | aad9b8ffe76c |
| branch: | default |
| tags: | tip |
p.50途中
Sho Hashimoto /
shokai
16 months ago
16 months ago
Changed (Δ704 bytes):
raw changeset »
03/zebo.rb (29 lines added, 0 lines removed)
1 |
#!/opt/local/bin/ruby |
|
2 |
||
3 |
require 'rubygems' |
|
4 |
require 'kconv' |
|
5 |
require 'open-uri' |
|
6 |
require 'hpricot' |
|
7 |
||
8 |
||
9 |
class Zebo |
|
10 |
||
11 |
# キーワード検索して商品詳細ページのURLリストを返す |
|
12 |
def wishpages(search='car', maxPage=4) |
|
13 |
urlList = Array.new |
|
14 |
for page in 1..maxPage # 10ページ |
|
15 |
puts 'processing page:' + page.to_s |
|
16 |
url = 'http://member.zebo.com/Main?event_key=USERSEARCH&action=ns&keyword='+search+'&tab=review&rPage='+page.to_s |
|
17 |
page = open(url).read().toutf8 |
|
18 |
doc = Hpricot(page) |
|
19 |
links = doc/:a |
|
20 |
links.each{ |link| |
|
21 |
urlList.push(link[:href]) if link[:href] =~ /http:\/\/reviews.zebo.com\/.*/ |
|
22 |
} |
|
23 |
end |
|
24 |
return urlList.uniq |
|
25 |
end |
|
26 |
||
27 |
end |
|
28 |
||
29 |
