baidu_web 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +10 -0
- data/lib/baidu_web/version.rb +1 -1
- data/lib/baidu_web.rb +4 -4
- metadata +1 -1
data/README.md
CHANGED
@@ -7,6 +7,12 @@ Baidu_web是一个基于百度的元搜索引擎,输入关键字,返还百
|
|
7
7
|
|
8
8
|
gem 'baidu_web'
|
9
9
|
|
10
|
+
## 依赖项
|
11
|
+
|
12
|
+
require 'mechanize'
|
13
|
+
require 'hpricot'
|
14
|
+
require 'open-uri'
|
15
|
+
|
10
16
|
## 调用
|
11
17
|
|
12
18
|
# http://www.baidu.com/s?wd=inruby&pn=100&rn=50
|
@@ -31,6 +37,10 @@ Baidu_web是一个基于百度的元搜索引擎,输入关键字,返还百
|
|
31
37
|
## 在irb中测试:
|
32
38
|
|
33
39
|
$:.unshift(File.dirname(__FILE__))
|
40
|
+
require 'mechanize'
|
41
|
+
require 'hpricot'
|
42
|
+
require 'open-uri'
|
34
43
|
require 'baidu_web'
|
35
44
|
require 'cgi'
|
36
45
|
result = BaiduWeb.search(CGI.escape("游戏"), :per_page => 10, :page_index => 1)
|
46
|
+
result = BaiduWeb.search("ruby", :per_page => 10, :page_index => 1)
|
data/lib/baidu_web/version.rb
CHANGED
data/lib/baidu_web.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
$:.unshift(File.dirname(__FILE__))
|
3
3
|
|
4
|
+
require 'mechanize'
|
4
5
|
require 'hpricot'
|
5
6
|
require 'open-uri'
|
6
|
-
|
7
|
-
#require 'cgi'
|
7
|
+
require 'cgi'
|
8
8
|
require "baidu_web/version"
|
9
9
|
require "baidu_web/record"
|
10
10
|
require "baidu_web/extension_key"
|
@@ -21,7 +21,7 @@ module BaiduWeb
|
|
21
21
|
@key_word = key_word
|
22
22
|
return result if @key_word.blank?
|
23
23
|
#uri parser key word
|
24
|
-
|
24
|
+
#@key_word = CGI.escape(@key_word)
|
25
25
|
|
26
26
|
#determine how many records display on one page. (same as www.baidu.com/?<some params>&rn=50)
|
27
27
|
@per_page = options[:per_page]
|
@@ -56,7 +56,7 @@ module BaiduWeb
|
|
56
56
|
# end
|
57
57
|
# }
|
58
58
|
|
59
|
-
return result if doc.
|
59
|
+
return result if doc.nil?
|
60
60
|
|
61
61
|
result[:record_arr] = extract_item(doc, item_index)
|
62
62
|
result[:ext_key_arr] = extract_extension_key(doc)
|