njongto_zon 0.0.3 → 0.0.7

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 +135 -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: 8efed34e848a50adfd7161d9801ca8b2519bf9e33977346dd169717e3c5e5613
4
+ data.tar.gz: 7b3dc04c6322b25c07602426a9f1872dbdbccf06f52d531c1f78ca0e50ab1b67
5
5
  SHA512:
6
- metadata.gz: 997ce0a7cf6e767a9ae76a3d2f8a1d76591d85c9d15bc51e3201c96331d2678aa6625428c677acee49ec010c0f8f4b305fca6190cb81893e4d8c73516d13d63d
7
- data.tar.gz: 7a90c424ae797e96ec73f771ea831d15ba698369c7d65b5e23fc57b740a02f8f9d536b02ca39c31392f82be4daf8b28a07777d1784b794a20eeaf92100818750
6
+ metadata.gz: 14b4cba0366a08d2060bea27ba8958ac9dea7b144e6285165784fde9f0b48951ed0c299862cc367d37919d5a4119d7c222c1c7aed35da44400c367405f5c0f35
7
+ data.tar.gz: 11434111e82544118425780d1b5c15c0a9bf18260fe8cddbdc1ba024594490f799468f941d0758248e4de31af58ca1e443804b357d3025a52f2361b4bceece3e
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,91 @@ 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
+ # ChromeDriver 경로 수동 지정
38
+ chromedriver_path = './chromedriver.exe'
39
+
40
+ # 웹드라이버 자동 업데이트 시도
41
+ begin
42
+ # webdrivers가 사용자의 Chrome 버전에 맞는 chromedriver 다운로드 시도
43
+ Webdrivers::Chromedriver.update # 자동 업데이트 시도
44
+ rescue => e
45
+ puts "webdrivers에서 chromedriver 다운로드 실패: #{e.message}"
46
+ puts "자동으로 chromedriver.exe 사용합니다."
47
+ puts "만일 프로그램 폴더안에 chromedriver.exe 버전이 맞지 않거나 없는 경우 인터넷창이 깜빡하고 닫히거나 열리지 않는경우에만 아래 안내를 따라주세요."
48
+ puts "https://storage.googleapis.com/chrome-for-testing-public/사용자크롬버전/win32/chromedriver-win32.zip 링크를 복사 후 복사 된 링크 중(사용자크롬버전) 부분을 크롬 사용자의 버전(예:131.0.6778.264)으로 수정 후 주소입력 부분에 넣어 엔터 후 다운로드 하고 압축을 풀고 chromedriver.exe 파일만 프로그램 폴더안에 넣어주세요."
49
+ puts "인터넷 창이 열리고 작업을 한다면 위 항목은 패스해주세요."
50
+ # 예외가 발생하면 수동 경로 사용
51
+ Selenium::WebDriver::Chrome::Service.driver_path = chromedriver_path
52
+ end
53
+
37
54
  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
55
+ begin
56
+ # webdrivers Gem이 크롬 드라이버 자동 다운로드 및 설정을 관리함
57
+ options = Selenium::WebDriver::Chrome::Options.new
58
+ options.page_load_strategy = :normal
59
+ options.timeouts = { page_load: 20_000 }
60
+ options.page_load_strategy = 'none'
61
+ options.add_argument('--disable-blink-features=AutomationControlled') #자동화된 환경에서 실행되는 것을 감지하는 기능을 비활성화합니다.
62
+
63
+
64
+
65
+ options.add_argument('--remote-debugging-port=9222')
66
+ options.add_argument("user-data-dir=#{naver_cookie_dir}/#{user_id}")
67
+
68
+ # :capabilities에 options를 배열로 전달
69
+ capabilities = [options]
70
+
71
+ # Selenium WebDriver에서 options를 capabilities로 전달
72
+ @driver = Selenium::WebDriver.for(:chrome, capabilities: capabilities)
73
+ rescue
74
+ options = Selenium::WebDriver::Chrome::Options.new
75
+ capabilities = [options]
76
+ # 예외 발생 시 다른 방법으로 셀레니움 실행
77
+ @driver = Selenium::WebDriver.for(:chrome, capabilities: capabilities)
78
+ end
50
79
  else
80
+ begin
81
+ # Proxy를 사용하는 경우
82
+ options = Selenium::WebDriver::Chrome::Options.new
83
+ options.add_argument '--proxy-server=' + proxy.to_s.force_encoding('utf-8')
84
+ options.page_load_strategy = :normal
85
+ options.timeouts = { page_load: 20_000 }
86
+ options.page_load_strategy = 'none'
87
+ options.add_argument('--disable-blink-features=AutomationControlled') #자동화된 환경에서 실행되는 것을 감지하는 기능을 비활성화합니다.
88
+
89
+ options.add_argument('--remote-debugging-port=9222')
90
+ options.add_argument("user-data-dir=#{naver_cookie_dir}/#{user_id}")
91
+
92
+ # :capabilities에 options를 배열로 전달
93
+ capabilities = [options]
94
+
95
+ # Selenium WebDriver에서 options를 capabilities로 전달
96
+ @driver = Selenium::WebDriver.for(:chrome, capabilities: capabilities)
97
+ rescue => e
98
+ puts 'proxy error...'
51
99
  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
100
+ # Proxy가 실패할 경우 예외 처리
101
+ options = Selenium::WebDriver::Chrome::Options.new
102
+ options.page_load_strategy = :normal
103
+ options.timeouts = { page_load: 20_000 }
104
+ options.page_load_strategy = 'none'
105
+ options.add_argument('--disable-blink-features=AutomationControlled') #자동화된 환경에서 실행되는 것을 감지하는 기능을 비활성화합니다.
106
+ options.add_argument('--remote-debugging-port=9222')
107
+ options.add_argument("user-data-dir=#{naver_cookie_dir}/#{user_id}")
108
+
109
+ # :capabilities에 options 배열로 전달
110
+ capabilities = [options]
111
+
112
+ @driver = Selenium::WebDriver.for(:chrome, capabilities: capabilities)
113
+ rescue
114
+ options = Selenium::WebDriver::Chrome::Options.new
115
+ capabilities = [options]
116
+ # 예외 발생 시 다른 방법으로 셀레니움 실행
117
+ @driver = Selenium::WebDriver.for(:chrome, capabilities: capabilities)
83
118
  end
119
+ end
84
120
  end
85
- end
121
+ end
86
122
 
87
123
 
88
124
 
@@ -195,10 +231,16 @@ class Naver
195
231
  @driver.switch_to.default_content()
196
232
  rescue
197
233
  #종토리뷰
198
- @driver.find_element(:xpath, '//*[@placeholder="제목"]')
199
- puts'[기능 발동!!] 오픈톡 유형 감지 확인.......'.green
200
- puts'[Step.04] 제목 입력.......'.yellow
201
- @driver.find_element(:xpath, '//*[@placeholder="제목"]').send_keys(title)
234
+ begin
235
+ @driver.find_element(:xpath, '//*[@placeholder="제목"]')
236
+ puts'[기능 발동!!] 오픈톡 유형 감지 확인.......'.green
237
+ puts'[Step.04] 제목 입력.......'.yellow
238
+ @driver.find_element(:xpath, '//*[@placeholder="제목"]').send_keys(title)
239
+ rescue
240
+ puts '[Error] 제목 입력란을 찾을 수 없습니다. 브라우저를 종료합니다.'.red
241
+ @driver.close
242
+ return 0
243
+ end
202
244
  end
203
245
 
204
246
  #내용 입력
@@ -213,9 +255,15 @@ class Naver
213
255
  @driver.switch_to.default_content()
214
256
  rescue
215
257
  #종토리뷰
258
+ begin
216
259
  @driver.find_element(:xpath, '//*[@placeholder="내용을 입력해 주세요."]')
217
260
  puts'[Step.05] 내용 입력.......'.yellow
218
261
  @driver.find_element(:xpath, '//*[@placeholder="내용을 입력해 주세요."]').click
262
+ rescue
263
+ puts '[Error] 내용 입력란을 찾을 수 없습니다. 브라우저를 종료합니다.'.red
264
+ @driver.close
265
+ return 0
266
+ end
219
267
  end
220
268
 
221
269
  puts content
@@ -281,11 +329,17 @@ class Naver
281
329
  puts'[Step.07] 등록 버튼 클릭 (성공).......'.yellow
282
330
  rescue
283
331
  #종토리뷰
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
332
+ begin
333
+ @driver.find_element(:xpath, '//*[@data-nclicks="nbw.ok"]')
334
+ sleep(1)
335
+ puts'[Step.06] 등록 버튼 클릭 (시도).......'.yellow
336
+ @driver.find_element(:xpath, '//*[@data-nclicks="nbw.ok"]').click
337
+ puts'[Step.07] 등록 버튼 클릭 (성공).......'.yellow
338
+ rescue
339
+ puts '[Error] 등록 버튼을 찾을 수 없습니다. 브라우저를 종료합니다.'.red
340
+ @driver.close
341
+ return 0
342
+ end
289
343
  end
290
344
  sleep(5)
291
345
  begin
@@ -327,17 +381,34 @@ class Wordpress
327
381
 
328
382
  #쿠키없을때 로그인하는 코드
329
383
 
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
384
+ def chrome_start(url, user_id, user_pw)
385
+ @url = url
386
+ @user_id = user_id
387
+ @user_pw = user_pw
388
+ begin
389
+ #Selenium::WebDriver::Chrome::Service.driver_path = './chromedriver.exe'
390
+ options = Selenium::WebDriver::Chrome::Options.new
391
+ options.page_load_strategy = :normal
392
+ options.timeouts = {page_load: 20_000}
393
+ options.page_load_strategy = 'none'
394
+ options.add_argument('--disable-blink-features=AutomationControlled') #자동화된 환경에서 실행되는 것을 감지하는 기능을 비활성화합니다.
395
+
396
+ options.add_argument('--remote-debugging-port=9222')
397
+ options.add_argument('user-data-dir=C:/naver_cookie/' + user_id)
398
+ # :capabilities에 options를 배열로 전달
399
+ capabilities = [options]
400
+
401
+ # Selenium WebDriver에서 options를 capabilities로 전달
402
+ @driver = Selenium::WebDriver.for(:chrome, capabilities: capabilities)
403
+ rescue
404
+ options = Selenium::WebDriver::Chrome::Options.new
405
+ # :capabilities에 options를 배열로 전달
406
+ capabilities = [options]
407
+
408
+ # Selenium WebDriver에서 options를 capabilities로 전달
409
+ @driver = Selenium::WebDriver.for(:chrome, capabilities: capabilities)
340
410
  end
411
+ end
341
412
 
342
413
 
343
414
 
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.7
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-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: File to Clipboard gem
14
14
  email: mymin26@naver.com