seotracker 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,8 @@
1
1
  = SeoTracker - получение позиций сайта в поисковиках.
2
2
 
3
- Например:
4
-
3
+ [Например:]
5
4
  seot = Seotracker::Google.new
5
+
6
6
  seot.get_position('serialmaniak.ru', 'серийный маньяк')
7
+
7
8
  -> 1
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.1.0
@@ -1,23 +1,30 @@
1
1
  require 'rubygems'
2
2
  require 'mechanize'
3
+ require 'logger'
3
4
 
4
5
  class Seotracker
5
6
  USER_AGENT = 'Mac Safari'
7
+ RESULTS = 10
6
8
 
7
9
  def initialize
8
10
  @agent = Mechanize.new
9
11
  @agent.user_agent_alias = Seotracker::USER_AGENT
12
+ @agent.agent.http.verify_mode = OpenSSL::SSL::VERIFY_NONE
13
+ @agent.agent.http.retry_change_requests = true
10
14
  end
11
15
 
12
- def get_position(site, &block)
13
- links = yield
14
- pos, found = 0, false
15
- links.each do |l|
16
- pos += 1
17
- href = l.attribute('href').value.downcase
18
- unless href.rindex(site).nil?
19
- found = true
20
- break
16
+ def get_position(site, word)
17
+ pos, found, start = 0, false, 0
18
+ while (start < 200) && !found
19
+ links = parse(word, start)
20
+ start += RESULTS
21
+ links.each do |l|
22
+ pos += 1
23
+ href = l.attribute('href').value.downcase
24
+ unless href.rindex(site).nil?
25
+ found = true
26
+ break
27
+ end
21
28
  end
22
29
  end
23
30
  found ? pos : 0
@@ -1,11 +1,10 @@
1
1
  class Seotracker::Google < Seotracker
2
- SEARCH_URL = 'http://www.google.ru/search?ix=seb&sourceid=chrome&ie=UTF-8'
2
+ SEARCH_URL = "http://www.google.ru/search?ix=seb&sourceid=chrome&ie=UTF-8"
3
3
 
4
- # получаем позицию сайта для слова
5
- def get_position(site, word)
6
- super(site) do
7
- page = @agent.get(SEARCH_URL, q: word)
8
- page.root.xpath('/html/body/div[5]/div/div/div[4]/div[2]/div[2]/div/div[2]/div/ol/li/div/h3/a')
9
- end
4
+ protected
5
+
6
+ def parse(word, start = 0)
7
+ page = @agent.get(SEARCH_URL, q: word, start: start)
8
+ page.root.xpath('/html/body/div[5]/div/div/div[4]/div[2]/div[2]/div/div[2]/div/ol/li/div/h3/a')
10
9
  end
11
10
  end
@@ -1,11 +1,24 @@
1
1
  class Seotracker::Yandex < Seotracker
2
- SEARCH_URL = 'http://yandex.ru/yandsearch'
2
+ SEARCH_URL = "http://yandex.ru/yandsearch?"
3
3
 
4
- # получаем позицию сайта для слова
5
- def get_position(site, word)
6
- super(site) do
7
- page = @agent.get(SEARCH_URL, text: word)
8
- page.root.xpath('/html/body/div[3]/div/div/div[2]/ol/li/div/h2/a')
4
+ protected
5
+
6
+ def parse(word, start = 0)
7
+ start /= 10
8
+
9
+ # у яндекса хитрая проверка на роботов
10
+ if start == 0
11
+ @agent.get('http://kiks.yandex.ru/su/')
12
+ @cookie = @agent.cookies.first
9
13
  end
14
+
15
+ #agent = Mechanize.new
16
+ #agent.user_agent_alias = Seotracker::USER_AGENT
17
+ ##agent.log = Logger.new('log.txt')
18
+
19
+ url = SEARCH_URL + "text=#{word}&p=#{start}"
20
+
21
+ page = @agent.get(url, [], nil, {'cookie' => @cookie})
22
+ page.root.xpath('/html/body/div[3]/div/div/div[2]/ol/li/div/h2/a')
10
23
  end
11
24
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "seotracker"
8
- s.version = "0.0.1"
8
+ s.version = "0.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["krivich ekaterina"]
12
- s.date = "2012-04-02"
12
+ s.date = "2012-04-03"
13
13
  s.description = "track sites position in google or yandex by keyword"
14
14
  s.email = "kiote_the_one@mail.ru"
15
15
  s.extra_rdoc_files = [
@@ -23,7 +23,9 @@ describe Seotracker do
23
23
 
24
24
  # мокаем все неважное
25
25
  mock = common_mocker
26
- mock.expect(:get, mock, [Seotracker::Yandex::SEARCH_URL, {text: @word}])
26
+ mock.expect(:get, mock, [Seotracker::Yandex::SEARCH_URL + "text=#{@word}&p=0", [], nil, {'cookie' => 'hi'}])
27
+ mock.expect(:get, mock, ['http://kiks.yandex.ru/su/'])
28
+ mock.expect(:cookies, ['hi'])
27
29
  mock.expect(:xpath, [mock], %w\/html/body/div[3]/div/div/div[2]/ol/li/div/h2/a\)
28
30
 
29
31
  @object.instance_variable_set(:@agent, mock)
@@ -40,7 +42,7 @@ describe Seotracker do
40
42
 
41
43
  # мокаем все неважное
42
44
  mock = common_mocker
43
- mock.expect(:get, mock, [Seotracker::Google::SEARCH_URL, {q: @word}])
45
+ mock.expect(:get, mock, [Seotracker::Google::SEARCH_URL, {q: @word, start: 0}])
44
46
  mock.expect(:xpath, [mock], %w\/html/body/div[5]/div/div/div[4]/div[2]/div[2]/div/div[2]/div/ol/li/div/h3/a\)
45
47
 
46
48
  @object.instance_variable_set(:@agent, mock)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seotracker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-02 00:00:00.000000000 Z
12
+ date: 2012-04-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest
16
- requirement: &70281779910940 !ruby/object:Gem::Requirement
16
+ requirement: &70225702846080 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70281779910940
24
+ version_requirements: *70225702846080
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: mechanize
27
- requirement: &70281779908660 !ruby/object:Gem::Requirement
27
+ requirement: &70225702845080 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70281779908660
35
+ version_requirements: *70225702845080
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: jeweler
38
- requirement: &70281779906360 !ruby/object:Gem::Requirement
38
+ requirement: &70225702844120 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70281779906360
46
+ version_requirements: *70225702844120
47
47
  description: track sites position in google or yandex by keyword
48
48
  email: kiote_the_one@mail.ru
49
49
  executables: []
@@ -79,7 +79,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
79
79
  version: '0'
80
80
  segments:
81
81
  - 0
82
- hash: 200424641832597920
82
+ hash: -195465089122756196
83
83
  required_rubygems_version: !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements: