nblog_zon 0.0.51 → 0.0.55

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/nblog_zon.rb +354 -259
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9a19858111ad3bada5d417c70f3f0690e8182bb4d559431c8289b65796dfc6ff
4
- data.tar.gz: 76d77623a63c8a330d775735a3f5f3f6c68fe96aaa7d0b12242d9842a8456e4a
3
+ metadata.gz: 5afd5e1aeacd5f7c0f4efd5f46afaf99c03040e5bbd654cf9d19b8ac2ef2c7d2
4
+ data.tar.gz: 8709907dccd6869df05ffe64d18df8b0478164bc9dfa0b26463f6d85b0ba6063
5
5
  SHA512:
6
- metadata.gz: bbdc3255da938fb1aa6cdf9f9de06f99652e75cf5b31f712f0fdf65a6cc21f21e18d4c264f6c7374b0b2ff60a1b5e7b6aaa4fb1a466366092afef343d49934ac
7
- data.tar.gz: 3cd4d3b7268ced3e87c59b894f64ab5b454ae6fd3ef0e135401cb8904fafcb290b18e148ff48c7f733eedc4a428c9a7fb95c3039f90a8bd211a675b670958409
6
+ metadata.gz: 5cefb322633f235adf3bc291ddae95de794eb6665b9c0d89cfdcc502c78e44f86e8e827758eb1cfd4042b254a009f8d4a687b8a69adc4901dbe02c3bb3761bb8
7
+ data.tar.gz: 1e1471975590f0ad7759e01f85b48f1a6a3aefbe8ea839600565c39c60f5e3a67c0e41d84d6d6d350f8611f179e54027c6bc2b93ee86e27e4e24589f7ecfd3a4
data/lib/nblog_zon.rb CHANGED
@@ -205,11 +205,14 @@ class Naver
205
205
  def initialize
206
206
  @seed = 1
207
207
  end
208
- def chrome_setup(user_id)
208
+ def chrome_setup(user_id, proxy)
209
209
  naver_cookie_dir = "C:/naver_cookie"
210
210
  FileUtils.mkdir_p(naver_cookie_dir) unless File.exist?(naver_cookie_dir)
211
+ if proxy == ''
211
212
  system(%{"C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe" https://naver.com/ --remote-debugging-port=9222 --user-data-dir=C:/naver_cookie/#{user_id}})
212
-
213
+ else
214
+ system(%{"C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe" "https://naver.com/" --remote-debugging-port=9222 --user-data-dir=C:/naver_cookie/#{user_id} --proxy-server=#{proxy.to_s.force_encoding('utf-8').to_s}})
215
+ end
213
216
  end
214
217
  def chrome_start(proxy, user_id)
215
218
  naver_cookie_dir = "C:/naver_cookie"
@@ -291,7 +294,7 @@ class Naver
291
294
  end
292
295
 
293
296
  # 새로운 스레드 생성 및 실행
294
- Thread.new { chrome_setup(user_id) }
297
+ Thread.new { chrome_setup(user_id, proxy) }
295
298
  sleep(3)
296
299
 
297
300
 
@@ -745,58 +748,182 @@ class Naver
745
748
  path = URI.decode_www_form(path)[0][0]
746
749
  if option['라이브러리사용안함'] == 'true'
747
750
  # 현재 탭의 URL을 가져오기
748
-
751
+ puts '라이브러리에서 제외되도록 작업을 실행합니다(새로운 창을 생성합니다)'
749
752
  posting_url = @driver.current_url
750
753
  @driver.execute_script("window.open('#{posting_url}');")
751
754
  sleep(1)
752
755
  @driver.switch_to.window(@driver.window_handles[1])
753
- wait = Selenium::WebDriver::Wait.new(timeout: 10)
754
- iframe = wait.until { @driver.find_element(id: 'mainFrame') }
755
- @driver.switch_to.frame(iframe)
756
756
  begin
757
- wait = Selenium::WebDriver::Wait.new(:timeout => 7)
758
- wait.until { @driver.find_element(:xpath, '//*[@class="se-popup-button-text"]') }
759
- @driver.find_element(:xpath, '//*[@class="se-popup-button-text"]').click
757
+ wait = Selenium::WebDriver::Wait.new(timeout: 10)
758
+ iframe = wait.until { @driver.find_element(id: 'mainFrame') }
759
+ @driver.switch_to.frame(iframe)
760
+ begin
761
+ wait = Selenium::WebDriver::Wait.new(:timeout => 7)
762
+ wait.until { @driver.find_element(:xpath, '//*[@class="se-popup-button-text"]') }
763
+ @driver.find_element(:xpath, '//*[@class="se-popup-button-text"]').click
764
+ sleep(1)
765
+ rescue
766
+ end
767
+ @driver.execute_script(<<~JS)
768
+ window.URL.createObjectURL = function() {};
769
+ HTMLInputElement.prototype.click = function() {
770
+ console.log("File dialog suppressed");
771
+ };
772
+ JS
760
773
  sleep(1)
761
- rescue
762
- end
763
- @driver.action.key_down(:control).key_down(:alt).send_keys('i').key_up(:alt).key_up(:control).perform
764
- sleep(1)
765
- Clipboard.copy(path.split('/').join("\\"))
766
- key_down('ctrl')
767
- key_stroke('v')
768
- key_up('ctrl')
769
- sleep(1)
770
- key_stroke('enter')
771
- sleep(2)
772
- @driver.action.send_keys(:up).perform
773
- sleep(1)
774
- @driver.action.key_down(:control).send_keys('c').key_up(:control).perform
775
- sleep(1)
776
- @driver.switch_to.default_content()
777
- @driver.close
778
- sleep(1)
779
- @driver.switch_to.window(@driver.window_handles[0])
780
- wait = Selenium::WebDriver::Wait.new(timeout: 10)
781
- iframe = wait.until { @driver.find_element(id: 'mainFrame') }
782
- @driver.switch_to.frame(iframe)
783
- #@driver.action.key_down(:control).send_keys('v').key_up(:control).perform
784
- key_down('ctrl')
785
- key_stroke('v')
786
- key_up('ctrl')
787
- sleep(1)
774
+
775
+ wait = Selenium::WebDriver::Wait.new(:timeout => 3)
776
+ # 요소가 나타날 때까지 기다립니다.
777
+ wait.until { @driver.find_element(:xpath, '//ul[@class="se-toolbar se-document-toolbar"]//li[@class="se-toolbar-item se-toolbar-item-image"]//button[@data-name="image"]') }
778
+ # 해당 버튼을 찾고 클릭
779
+ image_button = @driver.find_element(:xpath, '//ul[@class="se-toolbar se-document-toolbar"]//li[@class="se-toolbar-item se-toolbar-item-image"]//button[@data-name="image"]')
780
+ @driver.execute_script("arguments[0].scrollIntoView({block: 'center', inline: 'center'})", image_button) # 크롤 이동
781
+ sleep(1)
782
+ @driver.find_element(:xpath, '//ul[@class="se-toolbar se-document-toolbar"]//li[@class="se-toolbar-item se-toolbar-item-image"]//button[@data-name="image"]').click
783
+ sleep(1)
784
+
785
+ # 파일 경로 변환 (슬래시 -> 백슬래시)
786
+ file_path = path.split('/').join("\\") # 윈도우 스타일 경로로 변환
787
+ sleep(1)
788
+ # 파일 입력 필드 찾기 (input[type="file"])
789
+ file_input = @driver.find_element(:id, 'hidden-file')
790
+ sleep(1)
791
+ # send_keys로 파일 경로를 직접 입력하여 파일 업로드
792
+ file_input.send_keys(file_path)
793
+ sleep(3)
794
+ @driver.action.key_down(:up).key_up(:up).perform
795
+ sleep(1)
796
+
797
+ begin
798
+ wait = Selenium::WebDriver::Wait.new(:timeout => 3)
799
+ #요소가 나타날 때까지 60초 동안 기다립니다.
800
+ wait.until { @driver.find_element(:xpath, '//li[@class="se-toolbar-item se-toolbar-item-resizing"]//button[@data-name="image-resizing"]') }
801
+ element = @driver.find_element(:xpath, '//li[@class="se-toolbar-item se-toolbar-item-resizing"]//button[@data-name="image-resizing"]')
802
+ @driver.execute_script("arguments[0].scrollIntoView({block: 'center', inline: 'center'})", element) # 크롤 이동
803
+ sleep(1)
804
+ aria_expanded = element.attribute('aria-expanded')
805
+ if aria_expanded == 'false'
806
+ element.click
807
+ sleep(1) # 클릭 후 잠시 대기
808
+ else
809
+ end
810
+
811
+ begin
812
+ wait = Selenium::WebDriver::Wait.new(:timeout => 3)
813
+ #요소가 나타날 때까지 60초 동안 기다립니다.
814
+ wait.until { @driver.find_element(:xpath, '//li[@class="se-toolbar-item se-toolbar-item-resizing"]//div[@class="se-custom-layer-option se-custom-layer-option-resizing"]//div[@class="se-custom-layer-resizing-option-group"]//button[@class="se-custom-layer-resizing-reset-button"]') }
815
+ sleep(1)
816
+ @driver.find_element(:xpath, '//li[@class="se-toolbar-item se-toolbar-item-resizing"]//div[@class="se-custom-layer-option se-custom-layer-option-resizing"]//div[@class="se-custom-layer-resizing-option-group"]//button[@class="se-custom-layer-resizing-reset-button"]').click
817
+ sleep(1)
818
+ @driver.action.key_down(:enter).key_up(:enter).perform #엔터
819
+ sleep(1)
820
+ rescue
821
+ wait = Selenium::WebDriver::Wait.new(:timeout => 3)
822
+ #요소가 나타날 때까지 60초 동안 기다립니다.
823
+ wait.until { @driver.find_element(:xpath, '//li[@class="se-toolbar-item se-toolbar-item-resizing"]//div[@class="se-custom-layer-option se-custom-layer-option-resizing"]//div[@class="se-custom-layer-resizing-option-group"]//button[@class="se-custom-layer-resizing-reset-button"]//span[@class="se-custom-layer-resizing-reset-label" and text()="초기화"]') }
824
+ sleep(1)
825
+ @driver.find_element(:xpath, '//li[@class="se-toolbar-item se-toolbar-item-resizing"]//div[@class="se-custom-layer-option se-custom-layer-option-resizing"]//div[@class="se-custom-layer-resizing-option-group"]//button[@class="se-custom-layer-resizing-reset-button"]//span[@class="se-custom-layer-resizing-reset-label" and text()="초기화"]').click
826
+ sleep(1)
827
+ @driver.action.key_down(:enter).key_up(:enter).perform #엔터
828
+ sleep(1)
829
+ end
830
+ rescue
831
+ @driver.action.key_down(:down).key_up(:down).perform
832
+ end
833
+ sleep(2)
834
+ @driver.action.send_keys(:up).perform
835
+ sleep(1)
836
+ @driver.action.key_down(:control).send_keys('c').key_up(:control).perform
837
+ sleep(1)
838
+ @driver.switch_to.default_content()
839
+ @driver.close
840
+ sleep(1)
841
+ @driver.switch_to.window(@driver.window_handles[0])
842
+ wait = Selenium::WebDriver::Wait.new(timeout: 10)
843
+ iframe = wait.until { @driver.find_element(id: 'mainFrame') }
844
+ @driver.switch_to.frame(iframe)
845
+ @driver.action.key_down(:control).send_keys('v').key_up(:control).perform
846
+ sleep(1)
847
+ rescue => e
848
+ @driver.quit
849
+ puts '이미지 등록실패! 인터넷 접속 불량 및 로딩 지연 다음 작업을 실행합니다.'
850
+ return 0
851
+ end
788
852
 
789
853
  else
790
- #@driver.find_element(:xpath, '//*[@id="'+page_id+'"]/div[1]/div/header/div[1]/ul/li[1]/button').click
791
- @driver.action.key_down(:control).key_down(:alt).send_keys('i').key_up(:alt).key_up(:control).perform
792
- sleep(2)
793
- Clipboard.copy(path.split('/').join("\\"))
794
- key_down('ctrl')
795
- key_stroke('v')
796
- key_up('ctrl')
854
+ @driver.execute_script(<<~JS)
855
+ window.URL.createObjectURL = function() {};
856
+ HTMLInputElement.prototype.click = function() {
857
+ console.log("File dialog suppressed");
858
+ };
859
+ JS
797
860
  sleep(1)
798
- key_stroke('enter')
799
- sleep(2)
861
+ begin
862
+ wait = Selenium::WebDriver::Wait.new(:timeout => 3)
863
+ # 요소가 나타날 때까지 기다립니다.
864
+ wait.until { @driver.find_element(:xpath, '//ul[@class="se-toolbar se-document-toolbar"]//li[@class="se-toolbar-item se-toolbar-item-image"]//button[@data-name="image"]') }
865
+ # 해당 버튼을 찾고 클릭
866
+ image_button = @driver.find_element(:xpath, '//ul[@class="se-toolbar se-document-toolbar"]//li[@class="se-toolbar-item se-toolbar-item-image"]//button[@data-name="image"]')
867
+ @driver.execute_script("arguments[0].scrollIntoView({block: 'center', inline: 'center'})", image_button) # 크롤 이동
868
+ sleep(1)
869
+ @driver.find_element(:xpath, '//ul[@class="se-toolbar se-document-toolbar"]//li[@class="se-toolbar-item se-toolbar-item-image"]//button[@data-name="image"]').click
870
+ sleep(1)
871
+
872
+
873
+ # 파일 경로 변환 (슬래시 -> 백슬래시)
874
+ file_path = path.split('/').join("\\") # 윈도우 스타일 경로로 변환
875
+ sleep(1)
876
+ # 파일 입력 필드 찾기 (input[type="file"])
877
+ file_input = @driver.find_element(:id, 'hidden-file')
878
+ sleep(1)
879
+ # send_keys로 파일 경로를 직접 입력하여 파일 업로드
880
+ file_input.send_keys(file_path)
881
+ sleep(3)
882
+ @driver.action.key_down(:up).key_up(:up).perform
883
+ sleep(1)
884
+
885
+ begin
886
+ wait = Selenium::WebDriver::Wait.new(:timeout => 3)
887
+ #요소가 나타날 때까지 60초 동안 기다립니다.
888
+ wait.until { @driver.find_element(:xpath, '//li[@class="se-toolbar-item se-toolbar-item-resizing"]//button[@data-name="image-resizing"]') }
889
+ element = @driver.find_element(:xpath, '//li[@class="se-toolbar-item se-toolbar-item-resizing"]//button[@data-name="image-resizing"]')
890
+ @driver.execute_script("arguments[0].scrollIntoView({block: 'center', inline: 'center'})", element) # 크롤 이동
891
+ sleep(1)
892
+ aria_expanded = element.attribute('aria-expanded')
893
+ if aria_expanded == 'false'
894
+ element.click
895
+ sleep(1) # 클릭 후 잠시 대기
896
+ else
897
+ end
898
+
899
+ begin
900
+ wait = Selenium::WebDriver::Wait.new(:timeout => 3)
901
+ #요소가 나타날 때까지 60초 동안 기다립니다.
902
+ wait.until { @driver.find_element(:xpath, '//li[@class="se-toolbar-item se-toolbar-item-resizing"]//div[@class="se-custom-layer-option se-custom-layer-option-resizing"]//div[@class="se-custom-layer-resizing-option-group"]//button[@class="se-custom-layer-resizing-reset-button"]') }
903
+ sleep(1)
904
+ @driver.find_element(:xpath, '//li[@class="se-toolbar-item se-toolbar-item-resizing"]//div[@class="se-custom-layer-option se-custom-layer-option-resizing"]//div[@class="se-custom-layer-resizing-option-group"]//button[@class="se-custom-layer-resizing-reset-button"]').click
905
+ sleep(1)
906
+ @driver.action.key_down(:enter).key_up(:enter).perform #엔터
907
+ sleep(1)
908
+ rescue
909
+ wait = Selenium::WebDriver::Wait.new(:timeout => 3)
910
+ #요소가 나타날 때까지 60초 동안 기다립니다.
911
+ wait.until { @driver.find_element(:xpath, '//li[@class="se-toolbar-item se-toolbar-item-resizing"]//div[@class="se-custom-layer-option se-custom-layer-option-resizing"]//div[@class="se-custom-layer-resizing-option-group"]//button[@class="se-custom-layer-resizing-reset-button"]//span[@class="se-custom-layer-resizing-reset-label" and text()="초기화"]') }
912
+ sleep(1)
913
+ @driver.find_element(:xpath, '//li[@class="se-toolbar-item se-toolbar-item-resizing"]//div[@class="se-custom-layer-option se-custom-layer-option-resizing"]//div[@class="se-custom-layer-resizing-option-group"]//button[@class="se-custom-layer-resizing-reset-button"]//span[@class="se-custom-layer-resizing-reset-label" and text()="초기화"]').click
914
+ sleep(1)
915
+ @driver.action.key_down(:enter).key_up(:enter).perform #엔터
916
+ sleep(1)
917
+ end
918
+ rescue
919
+ @driver.action.key_down(:down).key_up(:down).perform
920
+ end
921
+ rescue => e
922
+ @driver.close
923
+ puts '이미지 등록실패! 인터넷 접속 불량 및 로딩 지연 다음 작업을 실행합니다.'
924
+ return 0
925
+ end
926
+
800
927
  end
801
928
 
802
929
 
@@ -828,217 +955,217 @@ class Naver
828
955
  sleep(1)
829
956
  end
830
957
 
831
-
832
- # end
833
- # components_value['src'] = 'https://blogfiles.pstatic.net'+image_data['item']['url']+'?type=w1'
834
- # components_value['internalResource'] = true
835
- # components_value['represent'] = true
836
- # components_value['path'] = image_data['item']['url']
837
- # components_value['domain'] = "https://blogfiles.pstatic.net"
838
- # components_value['fileSize'] = image_data['item']['fileSize'].to_i
839
- # components_value['width'] = image_data['item']['width'].to_i
840
- # components_value['widthPercentage'] = 0
841
- # components_value['height'] = image_data['item']['height'].to_i
842
- # components_value['fileName'] = image_data['item']['fileName'].to_i
843
- # components_value['caption'] = nil
844
- # if i2.to_s.split('href="')[1] != nil
845
- # components_value['link'] = CGI.unescape(i2.to_s.split('href="')[1].split('"')[0])
846
- # end
847
- # components_value['format'] = 'normal'
848
- # components_value['displayFormat'] = 'normal'
849
- # components_value['imageLoaded'] = true
850
- # components_value['contentMode'] = 'fit'
851
- # components_value['origin'] = {
852
- # 'srcFrom' => 'local',
853
- # '@ctype' => 'imageOrigin'
854
- # }
855
- # components_value['@ctype'] = 'image'
958
+
856
959
  elsif i2.to_s.include?('<video')
857
960
  path = i2.to_s.split('src="')[1].split('"')[0]
858
961
  path = URI.decode_www_form(path)[0][0]
962
+ begin
963
+ @driver.find_element(:xpath, '//*[@id="'+page_id+'"]/div[1]/div/header/div[1]/ul/li[3]/button').click
964
+ sleep(3)
965
+
966
+
967
+ @driver.execute_script(<<~JS)
968
+ window.URL.createObjectURL = function() {};
969
+ HTMLInputElement.prototype.click = function() {
970
+ console.log("File dialog suppressed");
971
+ };
972
+ JS
973
+ sleep(1)
974
+ # 파일 업로드 버튼 클릭 (이제 파일 선택 창이 뜨지 않음)
975
+ @driver.find_element(:xpath, '//*[@id="video-uploader-wrap"]/div/div/div[2]/fieldset/div[1]/button[1]').click
976
+ sleep(3)
977
+
978
+ file_path = path.split('/').join("\\") # 윈도우 스타일 경로로 변환
979
+ sleep(1)
980
+ # 파일 입력 필드 찾기 (input[type="file"])
981
+ file_input = @driver.find_element(:id, "hidden-input")
982
+ sleep(1)
983
+ # send_keys로 파일 경로를 직접 입력하여 파일 업로드
984
+ file_input.send_keys(file_path)
985
+ sleep(3)
986
+
987
+ @driver.find_element(:xpath, '//*[@id="nvu_inp_box_title"]').send_keys(title)
988
+ sleep(1)
989
+
990
+ @driver.find_element(:xpath, '//*[@id="nvu_inp_box_description"]').send_keys(title)
991
+ sleep(1)
992
+
993
+
994
+
995
+
996
+ tags2 = option['tag'].to_s
997
+ tag_mm2 = Array.new
998
+ tags2.split(',').each do |tag_value|
999
+ tag_mm2 << ''+tag_value
1000
+ end
1001
+
1002
+ @driver.find_element(:xpath, '//*[@id="nvu_inp_box_tag"]').send_keys(tag_mm2.join("\n")+"\n")
1003
+ sleep(1)
1004
+
859
1005
 
860
- @driver.find_element(:xpath, '//*[@id="'+page_id+'"]/div[1]/div/header/div[1]/ul/li[3]/button').click
861
- sleep(3)
862
- @driver.find_element(:xpath, '//*[@id="video-uploader-wrap"]/div/div/div[2]/fieldset/div[1]/button[1]').click
863
- sleep(3)
864
-
865
- Clipboard.copy(path.split('/').join("\\"))
866
- key_down('ctrl')
867
- key_stroke('v')
868
- key_up('ctrl')
869
- sleep(3)
870
- key_stroke('enter')
871
- sleep(3)
872
-
873
- for n in 1..10
874
- puts @driver.find_element(:xpath, '//*[@id="video-uploader-wrap"]/div/div/div[2]/div[1]/ul/li/div/button[1]/div[2]/em').text
875
- if @driver.find_element(:xpath, '//*[@id="video-uploader-wrap"]/div/div/div[2]/div[1]/ul/li/div/button[1]/div[2]/em').text == '업로드 완료'
876
- break
1006
+ for n in 1..10
1007
+ begin
1008
+ puts @driver.find_element(:xpath, '//*[@id="video-uploader-wrap"]/div/div/div[2]/div[1]/ul/li/div/button[1]/div[2]/em').text
1009
+ if @driver.find_element(:xpath, '//*[@id="video-uploader-wrap"]/div/div/div[2]/div[1]/ul/li/div/button[1]/div[2]/em').text == '업로드 완료'
1010
+ break
1011
+ end
1012
+ sleep(10)
1013
+ rescue
1014
+ end
877
1015
  end
878
- sleep(10)
1016
+
1017
+
1018
+ @driver.find_element(:xpath, '//*[@id="video-uploader-wrap"]/div/div/div[3]/button/span').click
1019
+ sleep(3)
1020
+ rescue => e
1021
+ @driver.close
1022
+ puts '동영상 등록실패! 인터넷 접속 불량 및 로딩 지연 다음 작업을 실행합니다.'
1023
+ return 0
879
1024
  end
880
- @driver.find_element(:xpath, '//*[@id="nvu_inp_box_title"]').send_keys(title)
881
- sleep(5)
882
- @driver.find_element(:xpath, '//*[@id="video-uploader-wrap"]/div/div/div[3]/button/span').click
883
- sleep(3)
884
-
885
1025
 
886
1026
  elsif i2.to_s.include?('<slide')
887
1027
  if option['라이브러리사용안함'] == 'true'
888
-
1028
+ puts '라이브러리에서 제외되도록 작업을 실행합니다(새로운 창을 생성합니다)'
889
1029
  posting_url = @driver.current_url
890
1030
  @driver.execute_script("window.open('#{posting_url}');")
891
1031
  sleep(1)
892
- @driver.switch_to.window(@driver.window_handles[1])
893
- wait = Selenium::WebDriver::Wait.new(timeout: 10)
894
- iframe = wait.until { @driver.find_element(id: 'mainFrame') }
895
- @driver.switch_to.frame(iframe)
1032
+
896
1033
  begin
1034
+ @driver.switch_to.window(@driver.window_handles[1])
1035
+ wait = Selenium::WebDriver::Wait.new(timeout: 10)
1036
+ iframe = wait.until { @driver.find_element(id: 'mainFrame') }
1037
+ @driver.switch_to.frame(iframe)
1038
+
1039
+
897
1040
  wait = Selenium::WebDriver::Wait.new(:timeout => 7)
898
1041
  wait.until { @driver.find_element(:xpath, '//*[@class="se-popup-button-text"]') }
899
1042
  @driver.find_element(:xpath, '//*[@class="se-popup-button-text"]').click
900
1043
  sleep(1)
901
- rescue
902
- end
903
-
904
- slide_content = i2.to_s.split('<slide>').last.split('</slide>').first.strip
905
- paths = slide_content.scan(/"([^"]+)"/).flatten # 큰따옴표로 감싸진 경로만 추출
1044
+
906
1045
 
907
- # 2. 전체 경로를 추출하여 윈도우 경로로 변환
908
- full_paths = paths.map { |path| path.strip.gsub('/', '\\') } # 윈도우 경로 구분자로 변경
1046
+ @driver.execute_script(<<~JS)
1047
+ window.URL.createObjectURL = function() {};
1048
+ HTMLInputElement.prototype.click = function() {
1049
+ console.log("File dialog suppressed");
1050
+ };
1051
+ JS
1052
+ sleep(1)
1053
+ # 기다릴 시간 설정
909
1054
 
910
- paths_with_quotes = full_paths.map { |path| "\"#{path}\"" }.join(' ')
911
- image_names = paths.map { |path| File.basename(path) }.map { |name| "\"#{name}\"" }.join(' ') # 큰따옴표로 감싼 파일 이름만 추출
912
- # 3. 전체 경로를 클립보드에 복사
913
- Clipboard.copy(paths_with_quotes)
1055
+ wait = Selenium::WebDriver::Wait.new(:timeout => 3)
1056
+ # 요소가 나타날 때까지 기다립니다.
1057
+ wait.until { @driver.find_element(:xpath, '//ul[@class="se-toolbar se-document-toolbar"]//li[@class="se-toolbar-item se-toolbar-item-image"]//button[@data-name="image"]') }
1058
+ # 해당 버튼을 찾고 클릭
1059
+ image_button = @driver.find_element(:xpath, '//ul[@class="se-toolbar se-document-toolbar"]//li[@class="se-toolbar-item se-toolbar-item-image"]//button[@data-name="image"]')
1060
+ @driver.execute_script("arguments[0].scrollIntoView({block: 'center', inline: 'center'})", image_button) # 크롤 이동
1061
+ sleep(1)
1062
+ @driver.find_element(:xpath, '//ul[@class="se-toolbar se-document-toolbar"]//li[@class="se-toolbar-item se-toolbar-item-image"]//button[@data-name="image"]').click
1063
+ sleep(2)
1064
+
1065
+ slide_content = i2.to_s.split('<slide>').last.split('</slide>').first.strip
914
1066
 
915
- # 4. 전체 경로를 붙여넣기
916
- @driver.find_element(:xpath, '//*[@class="se-toolbar-item se-toolbar-item-image"]').click
917
- sleep(1)
918
-
919
- key_down('ctrl')
920
- key_stroke('v')
921
- key_up('ctrl')
922
- sleep(1)
923
- key_stroke('enter')
924
- sleep(2)
925
- #@driver.action.key_down(:control).send_keys('z').key_up(:control).perform
926
- @driver.find_element(:xpath, '//*[@class="se-popup-close-button"]').click
1067
+ # 1. 큰따옴표로 감싸진 경로 추출
1068
+ paths = slide_content.scan(/"([^"]+)"/).flatten # 큰따옴표로 감싸진 경로만 추출
927
1069
 
928
- # 6. 이미지 이름만 클립보드에 복사 (큰따옴표 포함)
929
- Clipboard.copy(image_names)
930
-
931
- # 8. 이미지 이름만 클립보드에 복사 붙여넣기
932
- @driver.find_element(:xpath, '//*[@class="se-toolbar-item se-toolbar-item-image"]').click
933
- sleep(1)
934
- sleep(1)
935
- key_down('ctrl')
936
- key_stroke('v')
937
- key_up('ctrl')
938
- sleep(1)
939
- key_stroke('enter')
940
- sleep(2)
941
-
942
- wait = Selenium::WebDriver::Wait.new(:timeout => 10)
943
- wait.until { @driver.find_element(:xpath, '//*[@for="image-type-slide"]') }
944
- @driver.find_element(:xpath, '//*[@for="image-type-slide"]').click
945
- sleep(1)
946
- @driver.action.send_keys(:up).perform
947
- sleep(1)
948
- wait = Selenium::WebDriver::Wait.new(:timeout => 10)
949
- wait.until { @driver.find_element(:xpath, '//*[@data-log="ct.arrfit"]') }
950
- @driver.find_element(:xpath, '//*[@data-log="ct.arrfit"]').click
951
- sleep(1)
1070
+ # 2. 경로를 윈도우 형식으로 변경
1071
+ image_paths = paths.map { |path| path.strip.gsub('/', '\\') }
1072
+
1073
+ # 3. 여러 경로를 번에 전달할 수 있도록 줄바꿈으로 구분
1074
+ file_input = @driver.find_element(:id, 'hidden-file')
1075
+ sleep(1)
1076
+
1077
+ # 여러 파일 경로를 한 줄로 이어서 전달
1078
+ file_input.send_keys(image_paths.join("\n"))
1079
+ sleep(3)
1080
+
1081
+
952
1082
 
1083
+
1084
+ wait = Selenium::WebDriver::Wait.new(:timeout => 10)
1085
+ wait.until { @driver.find_element(:xpath, '//*[@for="image-type-slide"]') }
1086
+ @driver.find_element(:xpath, '//*[@for="image-type-slide"]').click
1087
+ sleep(1)
1088
+ @driver.action.send_keys(:up).perform
1089
+ sleep(1)
1090
+
953
1091
 
954
- @driver.action.key_down(:control).send_keys('c').key_up(:control).perform
955
- @driver.switch_to.default_content()
956
- @driver.close
957
- sleep(1)
958
- @driver.switch_to.window(@driver.window_handles[0])
959
- wait = Selenium::WebDriver::Wait.new(timeout: 10)
960
- iframe = wait.until { @driver.find_element(id: 'mainFrame') }
961
- @driver.switch_to.frame(iframe)
962
- #@driver.action.key_down(:control).send_keys('v').key_up(:control).perform
963
- key_down('ctrl')
964
- key_stroke('v')
965
- key_up('ctrl')
966
- sleep(1)
1092
+
1093
+ wait = Selenium::WebDriver::Wait.new(:timeout => 10)
1094
+ wait.until { @driver.find_element(:xpath, '//*[@data-log="ct.arrfit"]') }
1095
+ @driver.find_element(:xpath, '//*[@data-log="ct.arrfit"]').click
1096
+ sleep(1)
1097
+
1098
+ @driver.action.key_down(:control).send_keys('c').key_up(:control).perform
1099
+ @driver.switch_to.default_content()
1100
+ @driver.close
1101
+ sleep(1)
1102
+ @driver.switch_to.window(@driver.window_handles[0])
1103
+ wait = Selenium::WebDriver::Wait.new(timeout: 10)
1104
+ iframe = wait.until { @driver.find_element(id: 'mainFrame') }
1105
+ @driver.switch_to.frame(iframe)
1106
+ @driver.action.key_down(:control).send_keys('v').key_up(:control).perform
1107
+ rescue => e
1108
+ @driver.quit
1109
+ puts '이미지 등록실패! 인터넷 접속 불량 및 로딩 지연 다음 작업을 실행합니다.'
1110
+ return 0
1111
+ end
1112
+
967
1113
 
968
1114
  else
969
-
1115
+ @driver.execute_script(<<~JS)
1116
+ window.URL.createObjectURL = function() {};
1117
+ HTMLInputElement.prototype.click = function() {
1118
+ console.log("File dialog suppressed");
1119
+ };
1120
+ JS
1121
+ sleep(1)
1122
+ begin
1123
+ # 기다릴 시간 설정
1124
+ wait = Selenium::WebDriver::Wait.new(:timeout => 3)
1125
+ # 요소가 나타날 때까지 기다립니다.
1126
+ wait.until { @driver.find_element(:xpath, '//ul[@class="se-toolbar se-document-toolbar"]//li[@class="se-toolbar-item se-toolbar-item-image"]//button[@data-name="image"]') }
1127
+ # 해당 버튼을 찾고 클릭
1128
+ image_button = @driver.find_element(:xpath, '//ul[@class="se-toolbar se-document-toolbar"]//li[@class="se-toolbar-item se-toolbar-item-image"]//button[@data-name="image"]')
1129
+ @driver.execute_script("arguments[0].scrollIntoView({block: 'center', inline: 'center'})", image_button) # 크롤 이동
1130
+ sleep(1)
1131
+ @driver.find_element(:xpath, '//ul[@class="se-toolbar se-document-toolbar"]//li[@class="se-toolbar-item se-toolbar-item-image"]//button[@data-name="image"]').click
1132
+ sleep(2)
1133
+
970
1134
  slide_content = i2.to_s.split('<slide>').last.split('</slide>').first.strip
1135
+
1136
+ # 1. 큰따옴표로 감싸진 경로 추출
971
1137
  paths = slide_content.scan(/"([^"]+)"/).flatten # 큰따옴표로 감싸진 경로만 추출
972
-
973
- # 2. 전체 경로를 추출하여 윈도우 경로로 변환
974
- full_paths = paths.map { |path| path.strip.gsub('/', '\\') } # 윈도우 경로 구분자로 변경
975
-
976
- paths_with_quotes = full_paths.map { |path| "\"#{path}\"" }.join(' ')
977
- image_names = paths.map { |path| File.basename(path) }.map { |name| "\"#{name}\"" }.join(' ') # 큰따옴표로 감싼 파일 이름만 추출
978
- # 3. 전체 경로를 클립보드에 복사
979
- Clipboard.copy(paths_with_quotes)
980
1138
 
981
- # 4. 전체 경로를 붙여넣기
982
- @driver.find_element(:xpath, '//*[@id="'+page_id+'"]/div[1]/div/header/div[1]/ul/li[1]/button').click
983
- sleep(1)
984
-
985
- key_down('ctrl')
986
- key_stroke('v')
987
- key_up('ctrl')
1139
+ # 2. 경로를 윈도우 형식으로 변경
1140
+ image_paths = paths.map { |path| path.strip.gsub('/', '\\') }
1141
+
1142
+ # 3. 여러 경로를 한 번에 전달할 수 있도록 줄바꿈으로 구분
1143
+ file_input = @driver.find_element(:id, 'hidden-file')
988
1144
  sleep(1)
989
- key_stroke('enter')
990
- sleep(2)
991
-
992
- wait = Selenium::WebDriver::Wait.new(:timeout => 10)
993
- wait.until { @driver.find_element(:xpath, '//*[@class="se-popup-close-button"]') }
994
- @driver.find_element(:xpath, '//*[@class="se-popup-close-button"]').click
1145
+
1146
+ # 여러 파일 경로를 한 줄로 이어서 전달
1147
+ file_input.send_keys(image_paths.join("\n"))
1148
+ sleep(3)
995
1149
 
996
-
997
- # 6. 이미지 이름만 클립보드에 복사 (큰따옴표 포함)
998
- Clipboard.copy(image_names)
999
-
1000
- # 8. 이미지 이름만 클립보드에 복사 후 붙여넣기
1001
- @driver.find_element(:xpath, '//*[@id="'+page_id+'"]/div[1]/div/header/div[1]/ul/li[1]/button').click
1002
- sleep(1)
1003
- sleep(1)
1004
- key_down('ctrl')
1005
- key_stroke('v')
1006
- key_up('ctrl')
1007
- sleep(1)
1008
- key_stroke('enter')
1009
- sleep(2)
1010
-
1011
1150
  wait = Selenium::WebDriver::Wait.new(:timeout => 10)
1012
1151
  wait.until { @driver.find_element(:xpath, '//*[@for="image-type-slide"]') }
1013
1152
  @driver.find_element(:xpath, '//*[@for="image-type-slide"]').click
1014
1153
  sleep(1)
1015
1154
  @driver.action.send_keys(:up).perform
1016
1155
  sleep(1)
1017
-
1156
+
1018
1157
  wait = Selenium::WebDriver::Wait.new(:timeout => 10)
1019
1158
  wait.until { @driver.find_element(:xpath, '//*[@data-log="ct.arrfit"]') }
1020
1159
  @driver.find_element(:xpath, '//*[@data-log="ct.arrfit"]').click
1021
1160
  sleep(1)
1022
1161
  @driver.action.key_down(:enter).key_up(:enter).perform
1023
-
1024
-
1025
- end
1026
-
1027
-
1028
-
1029
-
1030
-
1031
-
1032
-
1033
-
1034
-
1035
-
1036
-
1037
-
1038
-
1039
-
1040
-
1041
-
1162
+ rescue => e
1163
+ @driver.close
1164
+ puts '이미지 등록실패! 인터넷 접속 불량 및 로딩 지연 다음 작업을 실행합니다.'
1165
+ return 0
1166
+ end
1167
+
1168
+ end
1042
1169
 
1043
1170
 
1044
1171
 
@@ -1633,18 +1760,10 @@ class Wordpress
1633
1760
 
1634
1761
  def get_naver_text(q)
1635
1762
  begin
1636
- #Selenium::WebDriver::Chrome::Service.driver_path = './chromedriver.exe'
1637
- options = Selenium::WebDriver::Chrome::Options.new
1638
- capabilities = [options]
1639
-
1640
- # Selenium WebDriver에서 options를 capabilities로 전달
1641
- @driver = Selenium::WebDriver.for(:chrome, capabilities: capabilities)
1763
+ Selenium::WebDriver::Chrome::Service.driver_path = './chromedriver.exe'
1764
+ @driver = Selenium::WebDriver.for :chrome
1642
1765
  rescue
1643
- # :capabilities에 options를 배열로 전달
1644
- capabilities = [options]
1645
-
1646
- # Selenium WebDriver에서 options를 capabilities로 전달
1647
- @driver = Selenium::WebDriver.for(:chrome, capabilities: capabilities)
1766
+ @driver = Selenium::WebDriver.for :chrome
1648
1767
  end
1649
1768
  @driver.get('https://search.naver.com/search.naver?display=15&f=&filetype=0&page=3&query='+q.to_s+'&research_url=&sm=tab_pge&start=16&where=web')
1650
1769
  noko = Nokogiri::HTML(@driver.page_source)
@@ -1674,18 +1793,10 @@ class Wordpress
1674
1793
 
1675
1794
  def get_naver_text2(keyword)
1676
1795
  begin
1677
- #Selenium::WebDriver::Chrome::Service.driver_path = './chromedriver.exe'
1678
- options = Selenium::WebDriver::Chrome::Options.new
1679
- capabilities = [options]
1680
-
1681
- # Selenium WebDriver에서 options를 capabilities로 전달
1682
- @driver = Selenium::WebDriver.for(:chrome, capabilities: capabilities)
1796
+ Selenium::WebDriver::Chrome::Service.driver_path = './chromedriver.exe'
1797
+ @driver = Selenium::WebDriver.for :chrome
1683
1798
  rescue
1684
- # :capabilities에 options를 배열로 전달
1685
- capabilities = [options]
1686
-
1687
- # Selenium WebDriver에서 options를 capabilities로 전달
1688
- @driver = Selenium::WebDriver.for(:chrome, capabilities: capabilities)
1799
+ @driver = Selenium::WebDriver.for :chrome
1689
1800
  end
1690
1801
  @driver.get('https://search.naver.com/search.naver?ssc=tab.blog.all&sm=tab_jum&query='+keyword.to_s)
1691
1802
  for n3 in 1..10
@@ -1727,26 +1838,10 @@ class Wordpress
1727
1838
  @user_id = user_id
1728
1839
  @user_pw = user_pw
1729
1840
  begin
1730
- #Selenium::WebDriver::Chrome::Service.driver_path = './chromedriver.exe'
1731
- options = Selenium::WebDriver::Chrome::Options.new
1732
- options.page_load_strategy = :normal
1733
- options.timeouts = {page_load: 20_000}
1734
- options.page_load_strategy = 'none'
1735
- options.add_argument('--disable-blink-features=AutomationControlled') #자동화된 환경에서 실행되는 것을 감지하는 기능을 비활성화합니다.
1736
-
1737
- options.add_argument('--remote-debugging-port=9222')
1738
- options.add_argument('user-data-dir=C:/naver_cookie/' + user_id)
1739
- # :capabilities에 options를 배열로 전달
1740
- capabilities = [options]
1741
-
1742
- # Selenium WebDriver에서 options를 capabilities로 전달
1743
- @driver = Selenium::WebDriver.for(:chrome, capabilities: capabilities)
1841
+ Selenium::WebDriver::Chrome::Service.driver_path = './chromedriver.exe'
1842
+ @driver = Selenium::WebDriver.for :chrome
1744
1843
  rescue
1745
- # :capabilities에 options를 배열로 전달
1746
- capabilities = [options]
1747
-
1748
- # Selenium WebDriver에서 options를 capabilities로 전달
1749
- @driver = Selenium::WebDriver.for(:chrome, capabilities: capabilities)
1844
+ @driver = Selenium::WebDriver.for :chrome
1750
1845
  end
1751
1846
  end
1752
1847
 
@@ -3102,7 +3197,7 @@ class Wordpress
3102
3197
  @data['table'].pop
3103
3198
 
3104
3199
  dd_time = @data['table'][index][10].to_s.force_encoding('utf-8').to_i
3105
- template_no = @data['table'][index][7].to_s.force_encoding('utf-8').to_i
3200
+ #template_no = @data['table'][index][7].to_s.force_encoding('utf-8').to_i
3106
3201
  naver.update(title,content,option,soosick_1,soosick_2, dd_time)
3107
3202
 
3108
3203
 
@@ -3490,7 +3585,7 @@ class Wordpress
3490
3585
  i3 = i.to_s.force_encoding('utf-8').to_s
3491
3586
  i2 = i3.split(',')
3492
3587
  @data['table'] << [false, i2[0].to_s, i2[1].to_s,i2[2].to_s,i2[3].to_s,i2[4].to_s,i2[5].to_s,i2[6].to_s, 1,1,1,0,0]
3493
- @data['table'] << [false, i2[0].to_s, i2[1].to_s,i2[2].to_s,i2[3].to_s,i2[4].to_s,i2[5].to_s,i2[6].to_s, 1,1,1,0,0]
3588
+ @data['table'] << [false, i2[0].to_s, i2[1].to_s, 1,1,1,0,0]
3494
3589
  @data['table'].pop
3495
3590
  end
3496
3591
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nblog_zon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.51
4
+ version: 0.0.55
5
5
  platform: ruby
6
6
  authors:
7
7
  - zon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-01-20 00:00:00.000000000 Z
11
+ date: 2025-02-05 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: File to Clipboard gem
14
14
  email: rnjstnswp123@naver.com