brand2csv 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +14 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +26 -0
  5. data/Gemfile +4 -0
  6. data/History.txt +121 -0
  7. data/LICENCE.txt +515 -0
  8. data/Manifest.txt +54 -0
  9. data/README.md +27 -0
  10. data/Rakefile +18 -0
  11. data/bin/brand2csv +100 -0
  12. data/brand2csv.gemspec +44 -0
  13. data/lib/brand2csv.rb +594 -0
  14. data/lib/brand2csv/version.rb +3 -0
  15. data/logs/aspen_08_08_1986.html +598 -0
  16. data/logs/post.rohdaten.httpfox +1 -0
  17. data/logs/post.rohdaten.mechanize +1 -0
  18. data/logs/protocol_swissreg.log +86 -0
  19. data/logs/result_01.10.2005.jsp +598 -0
  20. data/logs/sr1.jsp +449 -0
  21. data/logs/sr3.jsp +598 -0
  22. data/logs/start.jsp +350 -0
  23. data/logs/start2.jsp +434 -0
  24. data/protocol.2013.05.12.textile +56 -0
  25. data/protocol.2013.05.15.textile +49 -0
  26. data/protocol.2013.05.21.textile +84 -0
  27. data/spec/brand2csv_spec.rb +62 -0
  28. data/spec/csv_spec.rb +57 -0
  29. data/spec/data/aspectra/detail_00001_P-480296.html +531 -0
  30. data/spec/data/aspectra/detail_00002_P-482236.html +531 -0
  31. data/spec/data/aspectra/detail_00003_641074.html +539 -0
  32. data/spec/data/aspectra/first_results.html +600 -0
  33. data/spec/data/einfache_suche.html +434 -0
  34. data/spec/data/erweiterte_suche.html +446 -0
  35. data/spec/data/main.html +350 -0
  36. data/spec/data/result_short.html +606 -0
  37. data/spec/data/resultate_1.html +446 -0
  38. data/spec/data/resultate_2.html +446 -0
  39. data/spec/data/urner_wildheu/detail_00001_57862.2013.html +516 -0
  40. data/spec/data/urner_wildheu/first_results.html +598 -0
  41. data/spec/data/vereinfachte_1.html +847 -0
  42. data/spec/data/vereinfachte_detail_33.html +516 -0
  43. data/spec/detail_spec.rb +28 -0
  44. data/spec/short_spec.rb +55 -0
  45. data/spec/simple_search.rb +43 -0
  46. data/spec/spec_helper.rb +34 -0
  47. data/spec/support/core_ext/kernel.rb +26 -0
  48. data/spec/support/server_mock_helper.rb +143 -0
  49. data/spec/swissreg_spec.rb +45 -0
  50. data/spec/trademark_numbers_spec.rb +21 -0
  51. data/spec/utilities_spec.rb +83 -0
  52. data/spike.rb +491 -0
  53. data/spike_mechanize_swissreg.rb +312 -0
  54. data/spike_watir.rb +58 -0
  55. data/swissreg.rb +75 -0
  56. metadata +86 -7
@@ -0,0 +1,312 @@
1
+ #!/usr/bin/env ruby
2
+ require 'mechanize'
3
+ require 'prettyprint'
4
+ require 'optparse'
5
+
6
+ Useage = "Usage: #{File.basename(__FILE__)} timespan
7
+ Find all brands registered in switzerland during the given timespan.
8
+ The following examples valid timespan periods:
9
+ 1.10.2005
10
+ 1.10.2005-31.10.2005
11
+ 1.10.2005, 5.10.2005-31.10.2005
12
+ "
13
+ OptionParser.new do |opts|
14
+ opts.banner = Useage
15
+ opts.on("-h", "--help", "Show this help") do |v|
16
+ puts opts
17
+ exit
18
+ end
19
+ end.parse!
20
+ unless ARGV
21
+ puts Useage
22
+ exit 1
23
+ end
24
+
25
+ timespan = ARGV[0]
26
+
27
+ module Brand2csv do
28
+ # Weitere gesehene Fehler
29
+ bekannteFehler =
30
+ ['Das Datum ist ung', # ültig'
31
+ 'Es wurden keine Daten gefunden.',
32
+ 'Die Suchkriterien sind teilweise unzul', # ässig',
33
+ 'Geben Sie mindestens ein Suchkriterium ein',
34
+ 'Die Suche wurde abgebrochen, da die maximale Suchzeit von 60 Sekunden',
35
+ ]
36
+ end
37
+ $base_uri = 'https://www.swissreg.ch'
38
+ $start_uri = "#{$base_uri}/srclient/faces/jsp/start.jsp"
39
+
40
+ def writeResponse(filename, body)
41
+ ausgabe = File.open(filename, 'w+')
42
+ ausgabe.puts body
43
+ ausgabe.close
44
+ end
45
+
46
+ def view_state(response)
47
+ if match = /javax.faces.ViewState.*?value="([^"]+)"/u.match(response.force_encoding('utf-8'))
48
+ match[1]
49
+ else
50
+ ""
51
+ end
52
+ end
53
+
54
+ def parse_swissreg(timespan = "01.06.2007-10.06.2007", # sollte 377 Treffer ergeben, für 01.06.2007-10.06.2007, 559271 wurde in diesem Zeitraum registriert
55
+ marke = nil,
56
+ nummer =nil) # nummer = "559271" ergibt genau einen treffer
57
+
58
+ a = Mechanize.new { |agent|
59
+ # agent.user_agent_alias = 'Mac Safari'
60
+ agent.user_agent = 'Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20100101 Firefox/16.0'
61
+ # agent.redirection_limit = 5
62
+ agent.verify_mode = OpenSSL::SSL::VERIFY_NONE
63
+ }
64
+
65
+ page = a.get $start_uri # get a cookie for the session
66
+ content = a.get_file $start_uri
67
+ FileUtils.makedirs 'mechanize'
68
+ writeResponse('mechanize/main.html', content)
69
+ state = view_state(content)
70
+ data = [
71
+ ["autoScroll", "0,0"],
72
+ ["id_swissreg:_link_hidden_", ""],
73
+ ["id_swissreg_SUBMIT", "1"],
74
+ ["id_swissreg:_idcl", "id_swissreg_sub_nav_ipiNavigation_item0"],
75
+ ["javax.faces.ViewState", state],
76
+ ]
77
+
78
+ content = a.post($start_uri, data)
79
+ writeResponse('mechanize/einfache_suche.html', content.body)
80
+
81
+ data = [
82
+ ["autoScroll", "0,0"],
83
+ ["id_swissreg:_link_hidden_", ""],
84
+ ["id_swissreg_SUBMIT", "1"],
85
+ ["id_swissreg:_idcl", "id_swissreg_sub_nav_ipiNavigation_item0_item3"],
86
+ ["javax.faces.ViewState", state],
87
+ ]
88
+ # sr1 ist die einfache suche, sr3 die erweiterte Suche
89
+ path = "/srclient/faces/jsp/trademark/sr3.jsp"
90
+ response = a.post($base_uri + path, data)
91
+ writeResponse('mechanize/erweiterte_suche.html', response.body)
92
+ # Bis hier alles okay
93
+ criteria = [
94
+ ["autoScroll", "0,0"],
95
+ ["id_swissreg:_link_hidden_", ""],
96
+ # "id_swissreg:mainContent:id_cbxFormatChoice" 2 = Publikationsansicht 1 = Registeransicht
97
+ ["id_swissreg:mainContent:id_cbxFormatChoice", "1"],
98
+ ["id_swissreg:mainContent:id_ckbTMState", "1"], # "Hängige Gesuche 1
99
+ # ["id_swissreg:mainContent:id_ckbTMState", "2"], # "Gelöschte Gesuche 2
100
+ ["id_swissreg:mainContent:id_ckbTMState", "3"], # aktive Marken 3
101
+ # ["id_swissreg:mainContent:id_ckbTMState", "4"], # gelöschte Marken 4
102
+ ["id_swissreg:mainContent:id_cbxCountry", "CH"], # Auswahl Länder _ALL
103
+ # ["id_swissreg:mainContent:id_txf_tm_no", ""], # Marken Nr
104
+ ["id_swissreg:mainContent:id_txf_app_no", ""], # Gesuch Nr.
105
+ ["id_swissreg:mainContent:id_txf_applicant", ""], # Inhaber/in
106
+ ["id_swissreg:mainContent:id_txf_agent", ""], # Vertreter/in
107
+ ["id_swissreg:mainContent:id_txf_licensee", ""], # Lizenznehmer
108
+ ["id_swissreg:mainContent:id_txf_nizza_class", ""], # Nizza Klassifikation Nr.
109
+ # ["id_swissreg:mainContent:id_txf_appDate", timespan], # Hinterlegungsdatum
110
+ ["id_swissreg:mainContent:id_txf_expiryDate", ""], # Ablauf Schutzfrist
111
+ # Markenart: Individualmarke 1 Kollektivmarke 2 Garantiemarke 3
112
+ ["id_swissreg:mainContent:id_cbxTMTypeGrp", "_ALL"], # Markenart
113
+ ["id_swissreg:mainContent:id_cbxTMForm", "_ALL"], # Markentyp
114
+ ["id_swissreg:mainContent:id_cbxTMColorClaim", "_ALL"], # Farbanspruch
115
+ ["id_swissreg:mainContent:id_txf_pub_date", ""], # Publikationsdatum
116
+ # name="id_swissreg:mainContent:id_ckbTMChoice", "tm_lbl_applicant"], # />&#160;Inhaber/in</label></td>
117
+
118
+ # info zu Publikationsgrund id_swissreg:mainContent:id_ckbTMPubReason
119
+ ["id_swissreg:mainContent:id_ckbTMPubReason", "1"], #Neueintragungen
120
+ ["id_swissreg:mainContent:id_ckbTMPubReason", "2"], #Berichtigungen
121
+ ["id_swissreg:mainContent:id_ckbTMPubReason", "3"], #Verlängerungen
122
+ ["id_swissreg:mainContent:id_ckbTMPubReason", "4"], #Löschungen
123
+ ["id_swissreg:mainContent:id_ckbTMPubReason", "5"], #Inhaberänderungen
124
+ ["id_swissreg:mainContent:id_ckbTMPubReason", "6"], #Vertreteränderungen
125
+ ["id_swissreg:mainContent:id_ckbTMPubReason", "7"], #Lizenzänderungen
126
+ ["id_swissreg:mainContent:id_ckbTMPubReason", "8"], #Weitere Registeränderungen
127
+ ["id_swissreg:mainContent:id_ckbTMEmptyHits", "0"], # Leere Trefferliste anzeigen
128
+
129
+ # Angezeigte Spalten "id_swissreg:mainContent:id_ckbTMChoice"
130
+ ["id_swissreg:mainContent:id_ckbTMChoice", "tm_lbl_tm_text"], # Marke
131
+ # ["id_swissreg:mainContent:id_ckbTMChoice", "tm_lbl_state"], # Status
132
+ # ["id_swissreg:mainContent:id_ckbTMChoice", "tm_lbl_nizza_class"], # Nizza Klassifikation Nr.
133
+ # ["id_swissreg:mainContent:id_ckbTMChoice", "tm_lbl_no"], # disabled="disabled"], # Nummer
134
+ ["id_swissreg:mainContent:id_ckbTMChoice", "tm_lbl_applicant"], # Inhaber/in
135
+ ["id_swissreg:mainContent:id_ckbTMChoice", "tm_lbl_country"], # Land (Inhaber/in)
136
+ # ["id_swissreg:mainContent:id_ckbTMChoice", "tm_lbl_agent"], # Vertreter/in
137
+ # ["id_swissreg:mainContent:id_ckbTMChoice", "tm_lbl_licensee"], # Lizenznehmer/in
138
+ ["id_swissreg:mainContent:id_ckbTMChoice", "tm_lbl_app_date"], # Hinterlegungsdatum
139
+ # ["id_swissreg:mainContent:id_ckbTMChoice", "tm_lbl_expiry_date"], # Ablauf Schutzfrist
140
+ # ["id_swissreg:mainContent:id_ckbTMChoice", "tm_lbl_type_grp"], # Markenart
141
+ # ["id_swissreg:mainContent:id_ckbTMChoice", "tm_lbl_form"], # Markentyp
142
+ # ["id_swissreg:mainContent:id_ckbTMChoice", "tm_lbl_color_claim"], # Farbanspruch
143
+
144
+ ["id_swissreg:mainContent:id_cbxHitsPerPage", "100"], # Treffer pro Seite
145
+ ["id_swissreg:mainContent:id_ckbTMChoice", "tm_lbl_applicant"],
146
+ ["id_swissreg:mainContent:sub_fieldset:id_submit", "suchen"],
147
+ # ["id_swissreg:mainContent:sub_fieldset:id_reset", "0"],
148
+ ["id_swissreg_SUBMIT", "1"],
149
+ ["javax.faces.ViewState", state],
150
+ ]
151
+ if marke # Wortlaut der Marke
152
+ puts "Marke ist #{marke}"
153
+ criteria << ["id_swissreg:mainContent:id_txf_tm_text", marke]
154
+ else
155
+ puts "Keine Marke spezifiziert. #{marke.inspect}"
156
+ criteria << ["id_swissreg:mainContent:id_txf_tm_text", ""]
157
+ end
158
+ if timespan # Hinterlegungsdatum
159
+ puts "Hinterlegungsdatum ist #{timespan}"
160
+ criteria << ["id_swissreg:mainContent:id_txf_appDate", timespan] # Hinterlegungsdatum
161
+ else
162
+ puts "Keine Hinterlegungsdatum spezifiziert. #{timespan.inspect}"
163
+ criteria << ["id_swissreg:mainContent:id_txf_appDate", ""] # Hinterlegungsdatum
164
+ end
165
+ if nummer
166
+ puts "nummer ist #{timespan}"
167
+ criteria << ["id_swissreg:mainContent:id_txf_tm_no", nummer]
168
+ else
169
+ puts "Keine nummer spezifiziert. #{timespan.inspect}"
170
+ criteria << ["id_swissreg:mainContent:id_txf_tm_no", ""]
171
+ end
172
+
173
+ path = "/srclient/faces/jsp/trademark/sr3.jsp"
174
+ response = a.post($base_uri + path, criteria)
175
+ writeResponse('mechanize/resultate_1.html', response.body)
176
+ criteria<<['id_swissreg:mainContent:scroll_1idx2', 'idx2']
177
+ if false # does not work, returns to the extended search path
178
+ response = a.post($base_uri + path, criteria)
179
+ writeResponse('mechanize/resultate_2.html', response.body)
180
+ end
181
+
182
+ if false # Will try later
183
+ path = "/srclient/faces/jsp/trademark/sr3.jsp"
184
+ data_detail = [
185
+ ["autoScroll", "0,0"],
186
+ ["id_swissreg:_link_hidden_", ""],
187
+ ["id_swissreg_SUBMIT", "1"],
188
+ ["id_swissreg:_idcl", "id_swissreg_sub_nav_ipiNavigation_item0_item3"],
189
+ ["javax.faces.ViewState", state],
190
+ ]
191
+
192
+ response = a.post($base_uri + path, data_detail)
193
+ https://www.swissreg.ch/srclient/faces/jsp/trademark/sr30.jsp
194
+ end
195
+ end #
196
+ # parse_swissreg("01.06.2007-10.06.2007" , 'asp*')
197
+ require 'csv'
198
+ $results = []
199
+ $errors = Hash.new
200
+
201
+ class Marke < Struct.new(:name, :markennummer, :inhaber, :land, :hinterlegungsdatum, :zeile_1, :zeile_2, :zeile_3, :zeile_4, :plz, :ort)
202
+ end
203
+
204
+ AddressRegexp = /^(\d\d\d\d)\W*(.*)/
205
+ LineSplit = ', '
206
+ DefaultCountry = 'Schweiz'
207
+
208
+ def parseAddress(nummer, inhaber)
209
+ zeile_1, zeile_2, zeile_3, zeile_4, zeile_5, zeile_6 = inhaber.split(LineSplit)
210
+ ort = nil
211
+ plz = nil
212
+ if m = AddressRegexp.match(zeile_2)
213
+ zeile_2 = nil
214
+ plz = m[1]; ort = m[2]
215
+ elsif m = AddressRegexp.match(zeile_3)
216
+ zeile_3 = nil
217
+ plz = m[1]; ort = m[2]
218
+ elsif m = AddressRegexp.match(zeile_4)
219
+ zeile_4 = nil
220
+ plz = m[1]; ort = m[2]
221
+ elsif m = AddressRegexp.match(zeile_5)
222
+ zeile_5 = nil
223
+ plz = m[1]; ort = m[2]
224
+ else
225
+ puts "Achtung! Konnte Marke #{nummer} mit Inhaber #{inhaber} nicht parsen" if $VERBOSE
226
+ return nil, nil, nil, nil, nil, nil, nil, nil
227
+ end
228
+ return zeile_1, zeile_2, zeile_3, zeile_4, zeile_5, zeile_6, plz, ort
229
+ end
230
+
231
+ def fetchDetails(nummer) # takes a long time!
232
+ doc = nil
233
+ filename = "mechanize/detail_#{nummer}.html"
234
+ unless File.exists?(filename)
235
+ url = "https://www.swissreg.ch/srclient/faces/jsp/trademark/sr300.jsp?language=de&section=tm&id=#{nummer}"
236
+ a = Mechanize.new { |agent|
237
+ # agent.user_agent_alias = 'Mac Safari'
238
+ agent.user_agent = 'Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20100101 Firefox/16.0'
239
+ # agent.redirection_limit = 5
240
+ agent.verify_mode = OpenSSL::SSL::VERIFY_NONE
241
+ }
242
+ page = a.get $start_uri # get a cookie for the session
243
+ content = a.get_file url
244
+ writeResponse("mechanize/detail_#{nummer}.html", content)
245
+ end
246
+ doc = Nokogiri::Slop(File.open(filename))
247
+ path_name = "//html/body/form/div/div/fieldset/div/table/tbody/tr/td"
248
+ elem = doc.xpath(path_name).first
249
+ counter = 0
250
+ doc.xpath(path_name).each{
251
+ |td|
252
+ pp "#{counter}: #{td.text}" if $VERBOSE
253
+ counter += 1
254
+ next unless /^inhaber/i.match(td.text)
255
+ zeilen = []
256
+ doc.xpath(path_name)[counter].children.each{ |child| zeilen << child.text.gsub(LineSplit,'. ') unless child.text.length == 0 } # avoid adding <br>
257
+ if info = $errors[nummer]
258
+ info.inhaber = zeilen.join(LineSplit)
259
+ info.zeile_1, info.zeile_2, info.zeile_3, info.zeile_4, zeile_5, zeile_6, info.plz, info.ort = parseAddress(nummer, info.inhaber)
260
+ $results << info
261
+ else
262
+ bezeichnung = doc.xpath(path_name)[15]
263
+ inhaber = zeilen.join(LineSplit)
264
+ zeile_1, zeile_2, zeile_3, zeile_4, zeile_5, zeile_6, plz, ort = parseAddress(nummer, inhaber)
265
+ hinterlegungsdatum = doc.xpath(path_name)[7]
266
+ marke = Marke.new(bezeichnung, nummer, inhaber, DefaultCountry, hinterlegungsdatum, zeile_1, zeile_2, zeile_3, zeile_4, plz, ort )
267
+ $results << marke
268
+ end
269
+ }
270
+ end
271
+
272
+ def fetchresult(filename= 'mechanize/resultate_1.html')
273
+ nrFailures = 0
274
+ # doc = Nokogiri::Slop(inhalt)
275
+ doc = Nokogiri::Slop(File.open(filename))
276
+ path_name = "//html/body/form/div/div/fieldset/table/tbody/tr/td/table/tbody/tr"
277
+ elem = doc.xpath(path_name).first
278
+ doc.xpath(path_name).each{
279
+ |elem|
280
+ bezeichnung = elem.elements[1].text
281
+ land = elem.elements[4].text
282
+ next unless /#{DefaultCountry}/i.match(land)
283
+ inhaber = elem.elements[3].text
284
+ nummer = elem.elements[2].text
285
+ if bezeichnung.length == 0
286
+ bezeichnung = elem.children[1].children[0].children[0].children[0].attribute('src').to_s
287
+ end
288
+ zeile_1, zeile_2, zeile_3, zeile_4, zeile_5, zeile_6, plz, ort = parseAddress(nummer, inhaber)
289
+ if zeile_1
290
+ $results << Marke.new(bezeichnung, elem.elements[2].text, elem.elements[3].text, land, elem.elements[5].text,
291
+ zeile_1, zeile_2, zeile_3, zeile_4, plz, ort )
292
+ else
293
+ nrFailures += 1
294
+ $errors[nummer] = Marke.new(bezeichnung, elem.elements[2].text, elem.elements[3].text, land, elem.elements[5].text,
295
+ zeile_1, zeile_2, zeile_3, zeile_4, plz, ort )
296
+ end
297
+ }
298
+ puts "Es gab #{nrFailures} Fehler beim lesen von #{filename}" if $VERBOSE
299
+ end
300
+
301
+ pp 1
302
+ parse_swissreg(timespan)
303
+ pp 2
304
+ fetchresult
305
+ $errors.each{
306
+ |markennummer, info|
307
+ fetchDetails(markennummer)
308
+ }
309
+
310
+ CSV.open('ausgabe.csv', 'w') do |csv|
311
+ $results.each{ |x| csv << x }
312
+ end
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ # require 'selenium'
4
+ require 'watir'
5
+ require 'watir-webdriver'
6
+ require 'fileutils'
7
+ require 'pp'
8
+
9
+ # zum schnell von Hand testen
10
+ # client = Selenium::WebDriver::Remote::Http::Default.new
11
+ # client.timeout = 180 # seconds – default is 60
12
+
13
+ $cnt = 1
14
+ def saveStep(b, cnt = $cnt)
15
+ name = "watir/#{__FILE__}_#{cnt}.html".sub('.rb','')
16
+ ausgabe = File.open(name, "w+")
17
+ ausgabe.write(b.html)
18
+ $cnt += 1 if $cnt.to_i != 0
19
+
20
+ end
21
+ Swiss_reg_URL = 'https://www.swissreg.ch'
22
+ client = Selenium::WebDriver::Remote::Http::Default.new
23
+ browser = Watir::Browser.new :firefox #, :http_client => client
24
+ # browser = Watir::Browser.new :chrome #, :http_client => client
25
+ browser.goto Swiss_reg_URL
26
+ #browser = Watir::Browser.start "https://www.swissreg.ch"
27
+ saveStep(browser, 11)
28
+ browser.link(:id, "id_swissreg_sub_nav_ipiNavigation_item0").click
29
+ saveStep(browser, 12 )
30
+ browser.link(:id, "id_swissreg_sub_nav_ipiNavigation_item0_item3").click
31
+ saveStep(browser, 13 )
32
+ browser.text_field(:id, "id_swissreg:mainContent:id_txf_appDate").set("1.10.2011-5.10.2011")
33
+ saveStep(browser, 14 )
34
+ browser.button(:value,"suchen").click
35
+ saveStep(browser, 15)
36
+ aus = browser.text
37
+ ausgabe=File.open('watir/liste.txt','w+')
38
+ ausgabe.puts aus
39
+ ausgabe.close
40
+ browser.link(:id, "id_swissreg:mainContent:data:2:tm_no_detail:id_detail").click# puts browser.text
41
+ browser.images.each do |x|
42
+ idx += 1
43
+ # apparently the string accepted by the string method will not allow variable substitution
44
+ location = 'img_' + idx.to_s + '.png'
45
+ x.save(location)
46
+ end
47
+ puts browser.url
48
+ pp browser.windows.each{ |w|
49
+ pp w.url
50
+ # saveStep(w)
51
+ }
52
+ # window2 = Watir::Browser.attach(:url, "https://www.swissreg.ch/srclient/faces/jsp/trademark/sr30.jsp") stackLevel too deep
53
+ #window2 = Selenium::WebDriver::Firefox.attach(:url, "https://www.swissreg.ch/srclient/faces/jsp/trademark/sr30.jsp")
54
+ #saveStep(window2)
55
+ #aus = window2.text
56
+ ausgabe=File.open('watir/detail.txt','w+')
57
+ ausgabe.puts aus
58
+ ausgabe.close
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ require 'rubygems' if /^1\.8/.match(RUBY_VERSION)
4
+ require 'mechanize'
5
+ require 'prettyprint'
6
+
7
+ def writeResponse(filename)
8
+ ausgabe = File.open(filename, 'w+')
9
+ ausgabe.puts @agent.page.body
10
+ ausgabe.close
11
+ end
12
+
13
+ @agent = Mechanize.new { |agent|
14
+ agent.user_agent = 'Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20100101 Firefox/16.0'
15
+ agent.verify_mode = OpenSSL::SSL::VERIFY_NONE
16
+ }
17
+
18
+ @agent.get_file 'https://www.swissreg.ch/srclient/faces/jsp/start.jsp'
19
+ writeResponse("log_#{__LINE__}.html") # complains about missing
20
+ @agent.page.links[3].click
21
+ writeResponse("log_#{__LINE__}.html")
22
+ @state = @agent.page.form["javax.faces.ViewState"]
23
+ data = [
24
+ ["autoScroll", "0,0"],
25
+ ["id_swissreg:_link_hidden_", ""],
26
+ ["id_swissreg_SUBMIT", "1"],
27
+ ["id_swissreg:_idcl", "id_swissreg_sub_nav_ipiNavigation_item0"],
28
+ ["javax.faces.ViewState", @state],
29
+ ]
30
+ @agent.page.form['id_swissreg:_idcl'] = 'id_swissreg_sub_nav_ipiNavigation_item0'
31
+ @agent.page.forms.first.submit
32
+ writeResponse("log_#{__LINE__}.html")
33
+ data = [
34
+ ["autoScroll", "0,0"],
35
+ ["id_swissreg:_link_hidden_", ""],
36
+ ["id_swissreg_SUBMIT", "1"],
37
+ ["id_swissreg:_idcl", "id_swissreg_sub_nav_ipiNavigation_item0_item3"],
38
+ ["javax.faces.ViewState", @state],
39
+ ]
40
+ @agent.page.form['id_swissreg:_idcl'] = 'id_swissreg_sub_nav_ipiNavigation_item0_item3'
41
+ @agent.page.forms.first.submit
42
+ writeResponse("log_#{__LINE__}.html")
43
+ data = [
44
+ ["autoScroll", "0,829"],
45
+ ["id_swissreg:_link_hidden_", ""],
46
+ ["id_swissreg:mainContent:id_ckbTMState", "1"], # "Hängige Gesuche 1
47
+ ["id_swissreg:mainContent:id_ckbTMState", "3"], # "Hängige Gesuche 1
48
+ ["id_swissreg:mainContent:id_txf_tm_no", ""],# Marken Nr
49
+ ["id_swissreg:mainContent:id_txf_app_no", ""], # Gesuch Nr.
50
+ ["id_swissreg:mainContent:id_txf_tm_text", "asp*"],
51
+ ["id_swissreg:mainContent:id_txf_applicant", ""], # Inhaber/in
52
+ ["id_swissreg:mainContent:id_txf_agent", ""], # Vertreter/in
53
+ ["id_swissreg:mainContent:id_txf_licensee", ""], # Lizenznehmer
54
+ ["id_swissreg:mainContent:id_txf_nizza_class", ""], # Nizza Klassifikation Nr.
55
+ ["id_swissreg:mainContent:id_txf_appDate", "01.01.2000-31.12.2012"] ,
56
+ ["id_swissreg:mainContent:id_txf_expiryDate", ""], # Ablauf Schutzfrist
57
+ ["id_swissreg:mainContent:id_cbxTMTypeGrp", "_ALL"], # Markenart
58
+ ["id_swissreg:mainContent:id_cbxTMForm", "_ALL"], # Markentyp
59
+ ["id_swissreg:mainContent:id_cbxTMColorClaim", "_ALL"], # Farbanspruch
60
+ ["id_swissreg:mainContent:id_txf_pub_date", ""], # Publikationsdatum
61
+ ["id_swissreg:mainContent:id_ckbTMPubReason", '1'],
62
+ ["id_swissreg:mainContent:id_ckbTMPubReason", '2'],
63
+ ["id_swissreg:mainContent:id_cbxFormatChoice", "1"],
64
+ ["id_swissreg:mainContent:id_ckbTMChoice", "tm_lbl_tm_text"],
65
+ ["id_swissreg:mainContent:id_ckbTMChoice", "tm_lbl_applicant"],
66
+ ["id_swissreg:mainContent:id_ckbTMChoice", "tm_lbl_country"],
67
+ ["id_swissreg:mainContent:id_cbxHitsPerPage", 250], # Treffer pro Seite
68
+ ["id_swissreg:mainContent:sub_fieldset:id_submit", "suchen"],
69
+ ["id_swissreg_SUBMIT", "1"],
70
+ ["id_swissreg:_idcl", ""],
71
+ ["id_swissreg:_link_hidden_", ""],
72
+ ["javax.faces.ViewState", @state],
73
+ ]
74
+ @agent.post('https://www.swissreg.ch/srclient/faces/jsp/trademark/sr3.jsp', data)
75
+ writeResponse("log_#{__LINE__}.html")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brand2csv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Niklaus Giger, Yasuhiro Asaka, Zeno R.R. Davatz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-17 00:00:00.000000000 Z
11
+ date: 2017-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mechanize
@@ -168,10 +168,65 @@ description: |-
168
168
  brand2csv creates csv files for swiss brand registered in a specific time period.
169
169
  The csv contains the brand, link to image (if present), link to the detailinfo at swissreg.ch, name and address of owner (Inhaber)
170
170
  email: yasaka@ywesee.com, zdavatz@ywesee.com, ngiger@ywesee.com
171
- executables: []
171
+ executables:
172
+ - brand2csv
172
173
  extensions: []
173
174
  extra_rdoc_files: []
174
- files: []
175
+ files:
176
+ - ".gitignore"
177
+ - ".rspec"
178
+ - ".travis.yml"
179
+ - Gemfile
180
+ - History.txt
181
+ - LICENCE.txt
182
+ - Manifest.txt
183
+ - README.md
184
+ - Rakefile
185
+ - bin/brand2csv
186
+ - brand2csv.gemspec
187
+ - lib/brand2csv.rb
188
+ - lib/brand2csv/version.rb
189
+ - logs/aspen_08_08_1986.html
190
+ - logs/post.rohdaten.httpfox
191
+ - logs/post.rohdaten.mechanize
192
+ - logs/protocol_swissreg.log
193
+ - logs/result_01.10.2005.jsp
194
+ - logs/sr1.jsp
195
+ - logs/sr3.jsp
196
+ - logs/start.jsp
197
+ - logs/start2.jsp
198
+ - protocol.2013.05.12.textile
199
+ - protocol.2013.05.15.textile
200
+ - protocol.2013.05.21.textile
201
+ - spec/brand2csv_spec.rb
202
+ - spec/csv_spec.rb
203
+ - spec/data/aspectra/detail_00001_P-480296.html
204
+ - spec/data/aspectra/detail_00002_P-482236.html
205
+ - spec/data/aspectra/detail_00003_641074.html
206
+ - spec/data/aspectra/first_results.html
207
+ - spec/data/einfache_suche.html
208
+ - spec/data/erweiterte_suche.html
209
+ - spec/data/main.html
210
+ - spec/data/result_short.html
211
+ - spec/data/resultate_1.html
212
+ - spec/data/resultate_2.html
213
+ - spec/data/urner_wildheu/detail_00001_57862.2013.html
214
+ - spec/data/urner_wildheu/first_results.html
215
+ - spec/data/vereinfachte_1.html
216
+ - spec/data/vereinfachte_detail_33.html
217
+ - spec/detail_spec.rb
218
+ - spec/short_spec.rb
219
+ - spec/simple_search.rb
220
+ - spec/spec_helper.rb
221
+ - spec/support/core_ext/kernel.rb
222
+ - spec/support/server_mock_helper.rb
223
+ - spec/swissreg_spec.rb
224
+ - spec/trademark_numbers_spec.rb
225
+ - spec/utilities_spec.rb
226
+ - spike.rb
227
+ - spike_mechanize_swissreg.rb
228
+ - spike_watir.rb
229
+ - swissreg.rb
175
230
  homepage: https://github.com/zdavatz/brand2csv
176
231
  licenses:
177
232
  - GPLv3
@@ -192,9 +247,33 @@ required_rubygems_version: !ruby/object:Gem::Requirement
192
247
  version: '0'
193
248
  requirements: []
194
249
  rubyforge_project:
195
- rubygems_version: 2.5.1
250
+ rubygems_version: 2.6.8
196
251
  signing_key:
197
252
  specification_version: 4
198
253
  summary: brand2csv creates csv files for swiss brands
199
- test_files: []
200
- has_rdoc:
254
+ test_files:
255
+ - spec/brand2csv_spec.rb
256
+ - spec/csv_spec.rb
257
+ - spec/data/aspectra/detail_00001_P-480296.html
258
+ - spec/data/aspectra/detail_00002_P-482236.html
259
+ - spec/data/aspectra/detail_00003_641074.html
260
+ - spec/data/aspectra/first_results.html
261
+ - spec/data/einfache_suche.html
262
+ - spec/data/erweiterte_suche.html
263
+ - spec/data/main.html
264
+ - spec/data/result_short.html
265
+ - spec/data/resultate_1.html
266
+ - spec/data/resultate_2.html
267
+ - spec/data/urner_wildheu/detail_00001_57862.2013.html
268
+ - spec/data/urner_wildheu/first_results.html
269
+ - spec/data/vereinfachte_1.html
270
+ - spec/data/vereinfachte_detail_33.html
271
+ - spec/detail_spec.rb
272
+ - spec/short_spec.rb
273
+ - spec/simple_search.rb
274
+ - spec/spec_helper.rb
275
+ - spec/support/core_ext/kernel.rb
276
+ - spec/support/server_mock_helper.rb
277
+ - spec/swissreg_spec.rb
278
+ - spec/trademark_numbers_spec.rb
279
+ - spec/utilities_spec.rb