njongto_zon 0.0.2 → 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 +161 -101
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cc60d944dfad2420bf61662cd1a5120cbfa1f70a50b5cfce4fa404999d4bf1c4
4
- data.tar.gz: d643c43237dbfcb2c57a95ec44dc8b525ea94c804ec1f84e8888bdd53873635f
3
+ metadata.gz: 4d1fa96e9573c0e89bf1d031372d9f059d292248cb11f754f4889dc7c729baad
4
+ data.tar.gz: 3cd74c1a712a18abf4f989d5797582a03d35cb0c4b2be4b1accf1e0889555053
5
5
  SHA512:
6
- metadata.gz: e6c0a401bc43f48a4663529514dd407ba44b9d6a90a4cc22fbe77a7ed1d38ef07bfe4f5e29a108705bd3ffe3b55dbee9be7bce29ac36f2ff9c71b7b7cc24c152
7
- data.tar.gz: 0045cda8e944c80789011f259c63e5806be0bd08e0144219edc0b838ac4a91e3b201ab60566748c0e3d9f9044ff3d3458bc2eed18dc71f610c8b296e2190b9fe
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'
@@ -19,98 +19,122 @@ require 'auto_click'
19
19
  require 'rainbow/refinement'
20
20
  include AutoClickMethods
21
21
  using Rainbow
22
-
22
+ include Glimmer
23
23
 
24
24
  class Naver
25
25
  def initialize
26
26
  @seed = 1
27
- @cookie = ''
28
27
  end
28
+ def chrome_setup(user_id)
29
+ naver_cookie_dir = "C:/naver_cookie"
30
+ FileUtils.mkdir_p(naver_cookie_dir) unless File.exist?(naver_cookie_dir)
31
+ system(%{"C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe" https://naver.com/ --remote-debugging-port=9222 --user-data-dir=C:/naver_cookie/#{user_id}})
29
32
 
30
- def chrome_start(proxy)
33
+ end
34
+ def chrome_start(proxy, user_id)
35
+ naver_cookie_dir = "C:/naver_cookie"
36
+ FileUtils.mkdir_p(naver_cookie_dir) unless File.exist?(naver_cookie_dir)
37
+
31
38
  if proxy == ''
32
- begin
33
- Selenium::WebDriver::Chrome::Service.driver_path = './chromedriver.exe'
34
- options = Selenium::WebDriver::Chrome::Options.new
35
- options.page_load_strategy = :normal
36
- options.timeouts = {page_load: 20_000}
37
- options.page_load_strategy = 'none'
38
- @driver = Selenium::WebDriver.for(:chrome, capabilities: options)
39
- rescue
40
- @driver = Selenium::WebDriver.for(:chrome, capabilities: options)
41
- 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
42
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...'
43
83
  begin
44
- Selenium::WebDriver::Chrome::Service.driver_path = './chromedriver.exe'
45
- options = Selenium::WebDriver::Chrome::Options.new
46
- # profile = Selenium::WebDriver::Chrome::Profile.new
47
- # profile['network.proxy.type'] = 1
48
- # profile['network.proxy.http'] = proxy.split(':')[0]
49
- # profile['network.proxy.http_port'] = proxy.split(':')[1].to_i
50
- # options = Selenium::WebDriver::Chrome::Options.new
51
- # options.profile = profile
52
- options = Selenium::WebDriver::Chrome::Options.new
53
- options.add_argument '--proxy-server='+proxy.to_s.force_encoding('utf-8').to_s
54
- options.page_load_strategy = :normal
55
- options.timeouts = {page_load: 20_000}
56
- options.page_load_strategy = 'none'
57
- @driver = Selenium::WebDriver.for(:chrome, capabilities: options)
58
- rescue => e
59
- puts e
60
- puts 'proxy error...'
61
- begin
62
- Selenium::WebDriver::Chrome::Service.driver_path = './chromedriver.exe'
63
- options = Selenium::WebDriver::Chrome::Options.new
64
- options.page_load_strategy = :normal
65
- options.timeouts = {page_load: 20_000}
66
- options.page_load_strategy = 'none'
67
- @driver = Selenium::WebDriver.for(:chrome, capabilities: options)
68
- rescue
69
- @driver = Selenium::WebDriver.for(:chrome, capabilities: options)
70
- 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)
71
102
  end
103
+ end
72
104
  end
73
- end
105
+ end
74
106
 
75
107
 
76
108
 
77
109
  def login(user_id, user_pw, proxy)
78
110
  @user_id = user_id
79
111
  @user_id11 = user_id
80
- chrome_start(proxy)
112
+ current_dir = File.dirname(__FILE__)
113
+ naver_cookie_dir = "C:/naver_cookie"
114
+ FileUtils.mkdir_p(naver_cookie_dir) unless File.exist?(naver_cookie_dir)
115
+
116
+
117
+
118
+ unless File.exist?("C:/naver_cookie/" + user_id)
119
+ driverfile_src = File.join(current_dir, 'driverfile')
120
+ if Dir.exist?(driverfile_src)
121
+ FileUtils.cp_r(driverfile_src, "C:/naver_cookie/" + user_id)
122
+
123
+ end
124
+ end
125
+
126
+ # 새로운 스레드 생성 및 실행
127
+ Thread.new { chrome_setup(user_id) }
128
+ sleep(3)
129
+
130
+
131
+ chrome_start(proxy, user_id)
81
132
  @driver.get('https://www.naver.com')
82
133
  puts'[Step.01] 계정 로그인 및 세션 확인.......'.yellow
83
- sleep(1)
84
- user_cookie_file = Array.new
85
- begin
86
- Dir.entries('./cookie').each do |i|
87
- if i == '.' or i == '..'
88
134
 
89
- else
90
- user_cookie_file << i
91
- end
92
- end
93
- rescue
94
-
95
- end
96
- sleep(1)
97
- @cookie4 = Hash.new
98
- if user_cookie_file.include?(user_id+'.txt')
99
- f = File.open('./cookie/'+user_id+'.txt', 'r')
100
- @cookie4 = JSON.parse(f.read())
101
- f.close
102
- end
103
-
104
- begin
105
- @cookie4.each do |i|
106
- p i
107
- @driver.manage.add_cookie(name: i['name'], value: i['value'], same_site: i['same_site'], domain: i['domain'], path: i['path'])
108
- end
109
- rescue
110
135
 
111
- end
112
136
  sleep(1)
113
- @driver.get('https://www.naver.com')
137
+
114
138
  begin
115
139
  wait = Selenium::WebDriver::Wait.new(:timeout => 3)
116
140
  #요소가 나타날 때까지 3초 동안 기다립니다.
@@ -133,7 +157,7 @@ class Naver
133
157
  #요소가 나타날 때까지 3초 동안 기다립니다.
134
158
  wait.until { @driver.find_element(:xpath, '//*[@for="switch"]') }
135
159
  sleep(1.5)
136
- @driver.find_element(:xpath, '//*[@for="switch"]').click #ip 보호 해제
160
+ @driver.find_element(:xpath, '//*[@id="login_keep_wrap"]/div[1]/label').click
137
161
  sleep(1.5)
138
162
  @driver.find_element(:xpath, '//*[@id="id"]').click
139
163
  Clipboard.copy(user_id)
@@ -145,20 +169,21 @@ class Naver
145
169
  sleep(1.5)
146
170
  @driver.find_element(:xpath, '//*[@id="log.login"]').click
147
171
  sleep(2.5)
172
+
148
173
  else
149
174
  # @driver.switch_to.default_content
150
175
  end
151
176
 
152
- @cookie = ''
153
- cookie2 = Array.new
154
- @driver.manage.all_cookies.each do |i|
155
- puts i
156
- @cookie += i[:name]+'='+i[:value]+'; '
157
- cookie2 << i
158
- end
159
-
160
- File.open('./cookie/'+user_id+'.txt', 'w') do |ff|
161
- ff.write(cookie2.to_json)
177
+ begin
178
+ wait = Selenium::WebDriver::Wait.new(:timeout => 3)
179
+ #요소가 나타날 때까지 3초 동안 기다립니다.
180
+ wait.until { @driver.find_element(:xpath, '//*[@class="MyView-module__btn_logout___bsTOJ"]') }
181
+
182
+ rescue => e
183
+ puts '-[√] 로그인 실패!!.......'.red
184
+ puts e
185
+ @driver.close
186
+ return 0
162
187
  end
163
188
  end
164
189
 
@@ -190,10 +215,16 @@ class Naver
190
215
  @driver.switch_to.default_content()
191
216
  rescue
192
217
  #종토리뷰
193
- @driver.find_element(:xpath, '//*[@placeholder="제목"]')
194
- puts'[기능 발동!!] 오픈톡 유형 감지 확인.......'.green
195
- puts'[Step.04] 제목 입력.......'.yellow
196
- @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
197
228
  end
198
229
 
199
230
  #내용 입력
@@ -208,9 +239,15 @@ class Naver
208
239
  @driver.switch_to.default_content()
209
240
  rescue
210
241
  #종토리뷰
242
+ begin
211
243
  @driver.find_element(:xpath, '//*[@placeholder="내용을 입력해 주세요."]')
212
244
  puts'[Step.05] 내용 입력.......'.yellow
213
245
  @driver.find_element(:xpath, '//*[@placeholder="내용을 입력해 주세요."]').click
246
+ rescue
247
+ puts '[Error] 내용 입력란을 찾을 수 없습니다. 브라우저를 종료합니다.'.red
248
+ @driver.close
249
+ return 0
250
+ end
214
251
  end
215
252
 
216
253
  puts content
@@ -276,11 +313,17 @@ class Naver
276
313
  puts'[Step.07] 등록 버튼 클릭 (성공).......'.yellow
277
314
  rescue
278
315
  #종토리뷰
279
- @driver.find_element(:xpath, '//*[@data-nclicks="nbw.ok"]')
280
- sleep(1)
281
- puts'[Step.06] 등록 버튼 클릭 (시도).......'.yellow
282
- @driver.find_element(:xpath, '//*[@data-nclicks="nbw.ok"]').click
283
- 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
284
327
  end
285
328
  sleep(5)
286
329
  begin
@@ -322,17 +365,34 @@ class Wordpress
322
365
 
323
366
  #쿠키없을때 로그인하는 코드
324
367
 
325
- def chrome_start(url, user_id, user_pw)
326
- @url = url
327
- @user_id = user_id
328
- @user_pw = user_pw
329
- begin
330
- Selenium::WebDriver::Chrome::Service.driver_path = './chromedriver.exe'
331
- @driver = Selenium::WebDriver.for :chrome
332
- rescue
333
- @driver = Selenium::WebDriver.for :chrome
334
- 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)
335
394
  end
395
+ end
336
396
 
337
397
 
338
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.2
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-11-26 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