njongto_duo 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_duo.rb +112 -57
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4cf36f0647a9f00f4a7b86a3d4a0c1892b32f0125ac1bb2236e1edad1ebd1d2e
4
- data.tar.gz: 1862e048e5d52a06bd3d2d6ed915cc226c9249bb31b745d94e1e39cf62e652d9
3
+ metadata.gz: e36ac7cb8b231587d6f08860160d96daad4ac030abd00d53c71b829739ccd9ef
4
+ data.tar.gz: 80cf12a63b6a9a97fd1da5d3fa3fbcf2bd99b655d72ae225e2b1330a88414160
5
5
  SHA512:
6
- metadata.gz: 43cfc9f8e21432c43a774b29883eee89f3d2d1ae2e5ef69bcbc8e07f569153657749bfaad9ad8f2bb4b03ce097e9efbe82e38e8219674d00db48965879d08441
7
- data.tar.gz: 2cc4c4a88b30ce30f220be3614a542bc9d8aaeb3990b4f0f0d0b5fedd063ea08809a844c7cbb88dd49ae8e3f0e8288135aa6e1545a52d056456ec80a17a076c9
6
+ metadata.gz: 7f65169db094bcb97abed2cdc7763e8b075801742108a15712e9346fd4043391a632dd2c1e664c3f99c071e11546b05ebe0f54f98b60c2d4a615e33c50176f41
7
+ data.tar.gz: eb038c527282224625b22a98a11fdf8b8ee3b46d3405c6039a965dfefff121d681f8849c7f1758e8a0348865393d7a0c92e90c786dec47a3dc66464de21b1f4d
data/lib/njongto_duo.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
@@ -402,10 +440,27 @@ class Wordpress
402
440
  @user_id = user_id
403
441
  @user_pw = user_pw
404
442
  begin
405
- Selenium::WebDriver::Chrome::Service.driver_path = './chromedriver.exe'
406
- @driver = Selenium::WebDriver.for :chrome
443
+ #Selenium::WebDriver::Chrome::Service.driver_path = './chromedriver.exe'
444
+ options = Selenium::WebDriver::Chrome::Options.new
445
+ options.page_load_strategy = :normal
446
+ options.timeouts = {page_load: 20_000}
447
+ options.page_load_strategy = 'none'
448
+ options.add_argument('--disable-blink-features=AutomationControlled') #자동화된 환경에서 실행되는 것을 감지하는 기능을 비활성화합니다.
449
+
450
+ options.add_argument('--remote-debugging-port=9222')
451
+ options.add_argument('user-data-dir=C:/naver_cookie/' + user_id)
452
+ # :capabilities에 options를 배열로 전달
453
+ capabilities = [options]
454
+
455
+ # Selenium WebDriver에서 options를 capabilities로 전달
456
+ @driver = Selenium::WebDriver.for(:chrome, capabilities: capabilities)
407
457
  rescue
408
- @driver = Selenium::WebDriver.for :chrome
458
+ options = Selenium::WebDriver::Chrome::Options.new
459
+ # :capabilities에 options를 배열로 전달
460
+ capabilities = [options]
461
+
462
+ # Selenium WebDriver에서 options를 capabilities로 전달
463
+ @driver = Selenium::WebDriver.for(:chrome, capabilities: capabilities)
409
464
  end
410
465
  end
411
466
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: njongto_duo
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