njongto_zon 0.0.3 → 0.0.5

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/njongto_zon.rb +119 -64
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fb946eeaa9c923b00046bed9baae9eb45abbe57eda39e44e7feba4a9e1c819b1
4
- data.tar.gz: c74b61469baa0892f2a01aeb5c447203c11a4d6793069b13b338b9b8749e3d9c
3
+ metadata.gz: 4d1fa96e9573c0e89bf1d031372d9f059d292248cb11f754f4889dc7c729baad
4
+ data.tar.gz: 3cd74c1a712a18abf4f989d5797582a03d35cb0c4b2be4b1accf1e0889555053
5
5
  SHA512:
6
- metadata.gz: 997ce0a7cf6e767a9ae76a3d2f8a1d76591d85c9d15bc51e3201c96331d2678aa6625428c677acee49ec010c0f8f4b305fca6190cb81893e4d8c73516d13d63d
7
- data.tar.gz: 7a90c424ae797e96ec73f771ea831d15ba698369c7d65b5e23fc57b740a02f8f9d536b02ca39c31392f82be4daf8b28a07777d1784b794a20eeaf92100818750
6
+ metadata.gz: b5b5a1cac50deb839fda1ccfcdcf9c91ea30a2348155aed4fcf1074859a599dfc4704a3fee1e2d513a0f6f2d43093a5247bcdd028b8a579358b4b707ae668a76
7
+ data.tar.gz: c19503f6ccf0e6c6d5d9899d003bff93d015948bfc3f707bdbf81beb0b694c37dd102bd8d3442fd9e464266ff5cf3d904e6664c923b557d7b4c1e23f3d82e36e
data/lib/njongto_zon.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'glimmer-dsl-libui'
2
2
  require 'selenium-webdriver'
3
- # require 'webdrivers'
3
+ require 'webdrivers'
4
4
  require 'iconv'
5
5
  require 'nokogiri'
6
6
  require 'http'
@@ -34,55 +34,75 @@ class Naver
34
34
  def chrome_start(proxy, user_id)
35
35
  naver_cookie_dir = "C:/naver_cookie"
36
36
  FileUtils.mkdir_p(naver_cookie_dir) unless File.exist?(naver_cookie_dir)
37
+
37
38
  if proxy == ''
38
- begin
39
- Selenium::WebDriver::Chrome::Service.driver_path = './chromedriver.exe'
40
- options = Selenium::WebDriver::Chrome::Options.new
41
- options.page_load_strategy = :normal
42
- options.timeouts = {page_load: 20_000}
43
- options.page_load_strategy = 'none'
44
- options.add_argument('--remote-debugging-port=9222')
45
- options.add_argument('user-data-dir=C:/naver_cookie/' + user_id)
46
- @driver = Selenium::WebDriver.for(:chrome, capabilities: options)
47
- rescue
48
- @driver = Selenium::WebDriver.for(:chrome, capabilities: options)
49
- end
39
+ begin
40
+ # webdrivers Gem이 크롬 드라이버 자동 다운로드 및 설정을 관리함
41
+ options = Selenium::WebDriver::Chrome::Options.new
42
+ options.page_load_strategy = :normal
43
+ options.timeouts = { page_load: 20_000 }
44
+ options.page_load_strategy = 'none'
45
+ options.add_argument('--disable-blink-features=AutomationControlled') #자동화된 환경에서 실행되는 것을 감지하는 기능을 비활성화합니다.
46
+
47
+
48
+
49
+ options.add_argument('--remote-debugging-port=9222')
50
+ options.add_argument("user-data-dir=#{naver_cookie_dir}/#{user_id}")
51
+
52
+ # :capabilities에 options를 배열로 전달
53
+ capabilities = [options]
54
+
55
+ # Selenium WebDriver에서 options를 capabilities로 전달
56
+ @driver = Selenium::WebDriver.for(:chrome, capabilities: capabilities)
57
+ rescue
58
+ options = Selenium::WebDriver::Chrome::Options.new
59
+ capabilities = [options]
60
+ # 예외 발생 시 다른 방법으로 셀레니움 실행
61
+ @driver = Selenium::WebDriver.for(:chrome, capabilities: capabilities)
62
+ end
50
63
  else
64
+ begin
65
+ # Proxy를 사용하는 경우
66
+ options = Selenium::WebDriver::Chrome::Options.new
67
+ options.add_argument '--proxy-server=' + proxy.to_s.force_encoding('utf-8')
68
+ options.page_load_strategy = :normal
69
+ options.timeouts = { page_load: 20_000 }
70
+ options.page_load_strategy = 'none'
71
+ options.add_argument('--disable-blink-features=AutomationControlled') #자동화된 환경에서 실행되는 것을 감지하는 기능을 비활성화합니다.
72
+
73
+ options.add_argument('--remote-debugging-port=9222')
74
+ options.add_argument("user-data-dir=#{naver_cookie_dir}/#{user_id}")
75
+
76
+ # :capabilities에 options를 배열로 전달
77
+ capabilities = [options]
78
+
79
+ # Selenium WebDriver에서 options를 capabilities로 전달
80
+ @driver = Selenium::WebDriver.for(:chrome, capabilities: capabilities)
81
+ rescue => e
82
+ puts 'proxy error...'
51
83
  begin
52
- Selenium::WebDriver::Chrome::Service.driver_path = './chromedriver.exe'
53
- options = Selenium::WebDriver::Chrome::Options.new
54
- # profile = Selenium::WebDriver::Chrome::Profile.new
55
- # profile['network.proxy.type'] = 1
56
- # profile['network.proxy.http'] = proxy.split(':')[0]
57
- # profile['network.proxy.http_port'] = proxy.split(':')[1].to_i
58
- # options = Selenium::WebDriver::Chrome::Options.new
59
- # options.profile = profile
60
- options = Selenium::WebDriver::Chrome::Options.new
61
- options.add_argument '--proxy-server='+proxy.to_s.force_encoding('utf-8').to_s
62
- options.page_load_strategy = :normal
63
- options.timeouts = {page_load: 20_000}
64
- options.page_load_strategy = 'none'
65
- options.add_argument('--remote-debugging-port=9222')
66
- options.add_argument('user-data-dir=C:/naver_cookie/' + user_id)
67
- @driver = Selenium::WebDriver.for(:chrome, capabilities: options)
68
- rescue => e
69
- puts e
70
- puts 'proxy error...'
71
- begin
72
- Selenium::WebDriver::Chrome::Service.driver_path = './chromedriver.exe'
73
- options = Selenium::WebDriver::Chrome::Options.new
74
- options.page_load_strategy = :normal
75
- options.timeouts = {page_load: 20_000}
76
- options.page_load_strategy = 'none'
77
- options.add_argument('--remote-debugging-port=9222')
78
- options.add_argument('user-data-dir=C:/naver_cookie/' + user_id)
79
- @driver = Selenium::WebDriver.for(:chrome, capabilities: options)
80
- rescue
81
- @driver = Selenium::WebDriver.for(:chrome, capabilities: options)
82
- end
84
+ # Proxy가 실패할 경우 예외 처리
85
+ options = Selenium::WebDriver::Chrome::Options.new
86
+ options.page_load_strategy = :normal
87
+ options.timeouts = { page_load: 20_000 }
88
+ options.page_load_strategy = 'none'
89
+ options.add_argument('--disable-blink-features=AutomationControlled') #자동화된 환경에서 실행되는 것을 감지하는 기능을 비활성화합니다.
90
+ options.add_argument('--remote-debugging-port=9222')
91
+ options.add_argument("user-data-dir=#{naver_cookie_dir}/#{user_id}")
92
+
93
+ # :capabilities에 options 배열로 전달
94
+ capabilities = [options]
95
+
96
+ @driver = Selenium::WebDriver.for(:chrome, capabilities: capabilities)
97
+ rescue
98
+ options = Selenium::WebDriver::Chrome::Options.new
99
+ capabilities = [options]
100
+ # 예외 발생 시 다른 방법으로 셀레니움 실행
101
+ @driver = Selenium::WebDriver.for(:chrome, capabilities: capabilities)
83
102
  end
103
+ end
84
104
  end
85
- end
105
+ end
86
106
 
87
107
 
88
108
 
@@ -195,10 +215,16 @@ class Naver
195
215
  @driver.switch_to.default_content()
196
216
  rescue
197
217
  #종토리뷰
198
- @driver.find_element(:xpath, '//*[@placeholder="제목"]')
199
- puts'[기능 발동!!] 오픈톡 유형 감지 확인.......'.green
200
- puts'[Step.04] 제목 입력.......'.yellow
201
- @driver.find_element(:xpath, '//*[@placeholder="제목"]').send_keys(title)
218
+ begin
219
+ @driver.find_element(:xpath, '//*[@placeholder="제목"]')
220
+ puts'[기능 발동!!] 오픈톡 유형 감지 확인.......'.green
221
+ puts'[Step.04] 제목 입력.......'.yellow
222
+ @driver.find_element(:xpath, '//*[@placeholder="제목"]').send_keys(title)
223
+ rescue
224
+ puts '[Error] 제목 입력란을 찾을 수 없습니다. 브라우저를 종료합니다.'.red
225
+ @driver.close
226
+ return 0
227
+ end
202
228
  end
203
229
 
204
230
  #내용 입력
@@ -213,9 +239,15 @@ class Naver
213
239
  @driver.switch_to.default_content()
214
240
  rescue
215
241
  #종토리뷰
242
+ begin
216
243
  @driver.find_element(:xpath, '//*[@placeholder="내용을 입력해 주세요."]')
217
244
  puts'[Step.05] 내용 입력.......'.yellow
218
245
  @driver.find_element(:xpath, '//*[@placeholder="내용을 입력해 주세요."]').click
246
+ rescue
247
+ puts '[Error] 내용 입력란을 찾을 수 없습니다. 브라우저를 종료합니다.'.red
248
+ @driver.close
249
+ return 0
250
+ end
219
251
  end
220
252
 
221
253
  puts content
@@ -281,11 +313,17 @@ class Naver
281
313
  puts'[Step.07] 등록 버튼 클릭 (성공).......'.yellow
282
314
  rescue
283
315
  #종토리뷰
284
- @driver.find_element(:xpath, '//*[@data-nclicks="nbw.ok"]')
285
- sleep(1)
286
- puts'[Step.06] 등록 버튼 클릭 (시도).......'.yellow
287
- @driver.find_element(:xpath, '//*[@data-nclicks="nbw.ok"]').click
288
- puts'[Step.07] 등록 버튼 클릭 (성공).......'.yellow
316
+ begin
317
+ @driver.find_element(:xpath, '//*[@data-nclicks="nbw.ok"]')
318
+ sleep(1)
319
+ puts'[Step.06] 등록 버튼 클릭 (시도).......'.yellow
320
+ @driver.find_element(:xpath, '//*[@data-nclicks="nbw.ok"]').click
321
+ puts'[Step.07] 등록 버튼 클릭 (성공).......'.yellow
322
+ rescue
323
+ puts '[Error] 등록 버튼을 찾을 수 없습니다. 브라우저를 종료합니다.'.red
324
+ @driver.close
325
+ return 0
326
+ end
289
327
  end
290
328
  sleep(5)
291
329
  begin
@@ -327,17 +365,34 @@ class Wordpress
327
365
 
328
366
  #쿠키없을때 로그인하는 코드
329
367
 
330
- def chrome_start(url, user_id, user_pw)
331
- @url = url
332
- @user_id = user_id
333
- @user_pw = user_pw
334
- begin
335
- Selenium::WebDriver::Chrome::Service.driver_path = './chromedriver.exe'
336
- @driver = Selenium::WebDriver.for :chrome
337
- rescue
338
- @driver = Selenium::WebDriver.for :chrome
339
- end
368
+ def chrome_start(url, user_id, user_pw)
369
+ @url = url
370
+ @user_id = user_id
371
+ @user_pw = user_pw
372
+ begin
373
+ #Selenium::WebDriver::Chrome::Service.driver_path = './chromedriver.exe'
374
+ options = Selenium::WebDriver::Chrome::Options.new
375
+ options.page_load_strategy = :normal
376
+ options.timeouts = {page_load: 20_000}
377
+ options.page_load_strategy = 'none'
378
+ options.add_argument('--disable-blink-features=AutomationControlled') #자동화된 환경에서 실행되는 것을 감지하는 기능을 비활성화합니다.
379
+
380
+ options.add_argument('--remote-debugging-port=9222')
381
+ options.add_argument('user-data-dir=C:/naver_cookie/' + user_id)
382
+ # :capabilities에 options를 배열로 전달
383
+ capabilities = [options]
384
+
385
+ # Selenium WebDriver에서 options를 capabilities로 전달
386
+ @driver = Selenium::WebDriver.for(:chrome, capabilities: capabilities)
387
+ rescue
388
+ options = Selenium::WebDriver::Chrome::Options.new
389
+ # :capabilities에 options를 배열로 전달
390
+ capabilities = [options]
391
+
392
+ # Selenium WebDriver에서 options를 capabilities로 전달
393
+ @driver = Selenium::WebDriver.for(:chrome, capabilities: capabilities)
340
394
  end
395
+ end
341
396
 
342
397
 
343
398
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: njongto_zon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - zon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-12-11 00:00:00.000000000 Z
11
+ date: 2025-01-09 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: File to Clipboard gem
14
14
  email: mymin26@naver.com