gulesider 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -24,32 +24,54 @@ class ScreenScraper
24
24
  end
25
25
 
26
26
  def scraped_person_data
27
+ search_result = []
28
+
27
29
  vcard = @result.search "div.vcard"
28
- address = vcard.search("span.adr").first
30
+ profile_info = vcard.search "div.profile-info"
31
+
32
+ profile_info.search("p").each do |p|
33
+ name = vcard.search("span.given-name").text + " " + vcard.search("span.family-name").text
34
+ phone = p.search("span.tel > a").text.strip
35
+ address = p.search("span.adr")
36
+ street_name = address.search("span.street-address").text
37
+ postal_code = address.search("span.postal-code").text
38
+ city = address.search("span.locality").text
39
+ lat = address.search("span.latitude").text
40
+ long = address.search("span.longitude").text
41
+
42
+ if phone != ""
43
+ search_result.push SearchResult.new({
44
+ :person => true,
45
+ :name => name,
46
+ :phone => phone,
47
+ :street_name => street_name,
48
+ :postal_code => postal_code,
49
+ :city => city,
50
+ :latitude => lat,
51
+ :longitude => long
52
+ })
53
+ end
54
+ end
29
55
 
30
- return SearchResult.new({
31
- :person => true,
32
- :name => vcard.search("span.given-name").text + " " + vcard.search("span.family-name").text,
33
- :phone => vcard.search("li.tel:first-child").text,
34
- :street_name => address.search("span.street-address").text,
35
- :postal_code => address.search("span.postal-code").text,
36
- :city => address.search("span.locality").text,
37
- :latitude => address.search("span.latitude").text,
38
- :longitude => address.search("span.longitude").text
39
- })
56
+ return search_result
40
57
  end
41
58
 
42
59
  def scraped_company_data
60
+ search_result = []
43
61
  list = @result.search "#result-list"
44
- first_hit = list.search "div.company-hit:first-child"
62
+ hits = list.search("div.company-hit")
63
+
64
+ hits.each do |hit|
65
+ search_result.push SearchResult.new({
66
+ :company => true,
67
+ :name => hit.search("div.header").search("a").text,
68
+ :phone => hit.search("li.tel:first-child").text,
69
+ :street_name => hit.search("span.street-address").text,
70
+ :postal_code => hit.search("span.postal-code").text,
71
+ :city => hit.search("span.locality").text
72
+ })
73
+ end
45
74
 
46
- return SearchResult.new({
47
- :company => true,
48
- :name => first_hit.search("div.header").search("a").text,
49
- :phone => first_hit.search("li.tel:first-child").text,
50
- :street_name => first_hit.search("span.street-address").text,
51
- :postal_code => first_hit.search("span.postal-code").text,
52
- :city => first_hit.search("span.locality").text
53
- })
75
+ return search_result
54
76
  end
55
77
  end
@@ -2,8 +2,17 @@
2
2
  require 'gulesider'
3
3
 
4
4
  puts "Søker på gulesider.no"
5
- result = Gulesider.search("#{ARGV[0]}")
5
+
6
+ query = 46823378 #ARGV[0]
7
+ result = Gulesider.search("#{query}")
8
+
6
9
  puts ""
7
- puts "#{result[:name]}"
8
- address = "#{result[:street_name]}, #{result[:postal_code]} #{result[:city]}"
9
- puts address if address != ", "
10
+ puts "\t#{result.length} resultater"
11
+
12
+ result.each do |entry|
13
+ puts "\tNavn: " + entry[:name]
14
+ puts "\tNummer: " + entry[:phone]
15
+ address = "\t#{entry[:street_name]}, #{entry[:postal_code]} #{entry[:city]}"
16
+ puts address if !entry[:street_name].empty? and address != ", "
17
+ puts ""
18
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gulesider
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-01-02 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mechanize
16
- requirement: &70271940132260 !ruby/object:Gem::Requirement
16
+ requirement: &70330773791800 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '2.1'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70271940132260
24
+ version_requirements: *70330773791800
25
25
  description:
26
26
  email: mail@goeran.no
27
27
  executables: