본문 바로가기
Python

[python] 무료 이미지 호스팅 URL 가져오기

by 퍼포먼스마케팅코더 2022. 10. 17.
반응형

[python] 무료 이미지 호스팅 URL 가져오기

 

오늘은 아래와 같이 무료 이미지 호스팅 URL을 가져올 수 있는 방법에 대해 적어보기로 한다. 셀레늄으로 들어가서 특정 웹사이트에 클릭해서 그 무료 이미지로 된 영구 URL만 가져오는 방식이다. 이에 아주 간단하게 autoit를 통해 이미 가지고 있는 파일 디렉토리 주소만 업로드 해놓고 이미지 주소만 공유받아서 가져오는 방식이다. 

 

from __future__ import print_function
import gspread
from oauth2client.service_account import ServiceAccountCredentials
import os
from googleapiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools
from googleapiclient.http import MediaFileUpload, MediaIoBaseDownload
import pickle
import os.path
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
import  warnings
from    selenium import webdriver
from    selenium.webdriver.support.ui import WebDriverWait
from    selenium.webdriver.support import expected_conditions as EC
from    selenium.webdriver.common.by import By
from    selenium.webdriver.common.keys import Keys 
from    selenium.webdriver.common.action_chains import ActionChains
from    selenium.common.exceptions import NoSuchElementException,StaleElementReferenceException
from    bs4      import BeautifulSoup
import  time
import  pyperclip
import  requests
import  datetime
import  pymssql
import  pandas as pd
from  pandas.core.frame import DataFrame
import  matplotlib.pyplot as plt
import  chromedriver_autoinstaller
import  subprocess
from    selenium import webdriver
from    selenium.webdriver.chrome.options import Options
from    selenium.webdriver.common.alert import Alert
import  chromedriver_autoinstaller
import  subprocess
import  shutil 
import  xlrd
import  openpyxl 
import  pygsheets
import  csv
import  re
import  webbrowser
import  os
import  sys
import  urllib.request
import  json
from    pandas.io.json import json_normalize
import  hashlib
import  hmac
import  base64
import  numpy as np
import  autoit #autoit는 반드시 autoit 프로그램이 깔려있어야됨
import  pyautogui
from PIL import ImageGrab
try:
    from PIL import Image
except ImportError:
    import Image
import pytesseract
import cv2
import numpy as np
import glob
from googleapiclient.http import MediaFileUpload, MediaIoBaseDownload
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
import io

import youtube_dl
from youtube_transcript_api import YouTubeTranscriptApi

import pdfkit
from PyPDF2 import PdfFileReader, PdfFileWriter
from tika import parser
import pdfkit

warnings.filterwarnings('ignore')

try:
    shutil.rmtree(r"c:\chrometemp")  #쿠키 / 캐쉬파일 삭제
except FileNotFoundError:
    pass
subprocess.Popen(r'C:\Program Files\Google\Chrome\Application\chrome.exe --remote-debugging-port=9222 --user-data-dir="C:\chrometemp"') # 디버거 크롬 구동
option = Options()
option.add_experimental_option("debuggerAddress", "127.0.0.1:9222")
chrome_ver = chromedriver_autoinstaller.get_chrome_version().split('.')[0]
try:
    driver = webdriver.Chrome(f'./{chrome_ver}/chromedriver.exe', options=option)
except:
    chromedriver_autoinstaller.install(True)
    driver = webdriver.Chrome(f'./{chrome_ver}/chromedriver.exe', options=option)
driver.maximize_window() #최대창
time.sleep(2)
driver.implicitly_wait(10)

img_file_lists = [ 'C:/Users/user/raw/down/health/119/119.jpg',
'C:/Users/user/raw/down/health/120/120.jpg',
'C:/Users/user/raw/down/health/121/121.jpg',
'C:/Users/user/raw/down/health/122/122.jpg',
'C:/Users/user/raw/down/health/123/123.jpg',
'C:/Users/user/raw/down/health/124/124.jpg',
'C:/Users/user/raw/down/health/125/125.jpg',
'C:/Users/user/raw/down/health/126/126.jpg',
'C:/Users/user/raw/down/health/127/127.jpg',
'C:/Users/user/raw/down/health/128/128.jpg',
'C:/Users/user/raw/down/health/129/129.jpg',
'C:/Users/user/raw/down/health/130/130.jpg',
'C:/Users/user/raw/down/health/131/131.jpg',
'C:/Users/user/raw/down/health/132/132.jpg',
'C:/Users/user/raw/down/health/133/133.jpg',
'C:/Users/user/raw/down/health/134/134.jpg',
'C:/Users/user/raw/down/health/135/135.jpg',
'C:/Users/user/raw/down/health/136/136.jpg',
'C:/Users/user/raw/down/health/137/137.jpg',
'C:/Users/user/raw/down/health/138/138.jpg',
'C:/Users/user/raw/down/health/139/139.jpg',
'C:/Users/user/raw/down/health/140/140.jpg',
'C:/Users/user/raw/down/health/141/141.jpg',
'C:/Users/user/raw/down/health/142/142.jpg',
'C:/Users/user/raw/down/health/143/143.jpg',
'C:/Users/user/raw/down/health/144/144.jpg',
'C:/Users/user/raw/down/health/145/145.jpg',
'C:/Users/user/raw/down/health/146/146.jpg',
'C:/Users/user/raw/down/health/147/147.jpg',
'C:/Users/user/raw/down/health/148/148.jpg',
'C:/Users/user/raw/down/health/149/149.jpg',
'C:/Users/user/raw/down/health/150/150.jpg',
'C:/Users/user/raw/down/health/151/151.jpg',
'C:/Users/user/raw/down/health/152/152.jpg',
'C:/Users/user/raw/down/health/153/153.jpg',
'C:/Users/user/raw/down/health/154/154.jpg',
'C:/Users/user/raw/down/health/155/155.jpg',
'C:/Users/user/raw/down/health/156/156.jpg',
'C:/Users/user/raw/down/health/157/157.jpg',
'C:/Users/user/raw/down/health/158/158.jpg',
'C:/Users/user/raw/down/health/159/159.jpg',
'C:/Users/user/raw/down/health/160/160.jpg',
'C:/Users/user/raw/down/health/161/161.jpg',
'C:/Users/user/raw/down/health/162/162.jpg',
'C:/Users/user/raw/down/health/163/163.jpg',
'C:/Users/user/raw/down/health/164/164.jpg',
'C:/Users/user/raw/down/health/165/165.jpg',
'C:/Users/user/raw/down/health/166/166.jpg',
'C:/Users/user/raw/down/health/167/167.jpg',
'C:/Users/user/raw/down/health/168/168.jpg',
'C:/Users/user/raw/down/health/169/169.jpg',
'C:/Users/user/raw/down/health/170/170.jpg',
'C:/Users/user/raw/down/health/171/171.jpg',
'C:/Users/user/raw/down/health/172/172.jpg',
'C:/Users/user/raw/down/health/173/173.jpg',
'C:/Users/user/raw/down/health/174/174.jpg',
'C:/Users/user/raw/down/health/175/175.jpg',
'C:/Users/user/raw/down/health/176/176.jpg',
'C:/Users/user/raw/down/health/177/177.jpg',
'C:/Users/user/raw/down/health/178/178.jpg',
'C:/Users/user/raw/down/health/179/179.jpg',
'C:/Users/user/raw/down/health/180/180.jpg',
'C:/Users/user/raw/down/health/181/181.jpg',
'C:/Users/user/raw/down/health/182/182.jpg',
'C:/Users/user/raw/down/health/183/183.jpg',
'C:/Users/user/raw/down/health/184/184.jpg',
'C:/Users/user/raw/down/health/185/185.jpg',
'C:/Users/user/raw/down/health/186/186.jpg',
'C:/Users/user/raw/down/health/187/187.jpg',
'C:/Users/user/raw/down/health/188/188.jpg',
'C:/Users/user/raw/down/health/189/189.jpg',
'C:/Users/user/raw/down/health/190/190.jpg',
'C:/Users/user/raw/down/health/191/191.jpg',
'C:/Users/user/raw/down/health/192/192.jpg',
'C:/Users/user/raw/down/health/193/193.jpg',
'C:/Users/user/raw/down/health/194/194.jpg',
'C:/Users/user/raw/down/health/195/195.jpg',
'C:/Users/user/raw/down/health/196/196.jpg',
'C:/Users/user/raw/down/health/197/197.jpg',
'C:/Users/user/raw/down/health/198/198.jpg',
'C:/Users/user/raw/down/health/199/199.jpg',
'C:/Users/user/raw/down/health/200/200.jpg',
'C:/Users/user/raw/down/health/201/201.jpg',
'C:/Users/user/raw/down/health/202/202.jpg',
'C:/Users/user/raw/down/health/203/203.jpg',
'C:/Users/user/raw/down/health/204/204.jpg',
'C:/Users/user/raw/down/health/205/205.jpg',
'C:/Users/user/raw/down/health/206/206.jpg'
]


for i in img_file_lists :
    url = 'http://15.165.222.35/'

    driver.get(url)

    time.sleep(1)
    driver.implicitly_wait(10)

    driver.find_element_by_css_selector('#dropzone').click()

    time.sleep(1)
    driver.implicitly_wait(10)

    handle = "[CLASS:#32770; TITLE:열기]" #Basic Window info 값 handle 변수에 저장
    autoit.win_wait_active("열기", 3)  #이름이 '열기'인 창이 나올 때까지 3초간 대기

    img_path = str(i) #이미지경로
    img_path_2 = img_path.replace('/', '\\') # 백슬래시는 두번 써야됨

    autoit.control_send(handle, "Edit1", img_path_2) #사진 클릭시 나오는 윈도우 창에서 파일이름(N)에 이미지 경로값 전달
    time.sleep(1)
    driver.implicitly_wait(10)
    
    autoit.control_click(handle, "Button1") #사진 클릭시 나오는 윈도우 창에서 Button1 클릭
    time.sleep(1)
    driver.implicitly_wait(10)

    html = driver.page_source

    raw = BeautifulSoup(html, 'html.parser')
    results = raw.find('div', {'id' : 'uploadinfo'}).find_all('a')
    
    print('파일 디렉토리 : ' +str(i) +' 이미지 주소: ' +results[1].text)
    
    time.sleep(1) #1초
    
driver.close()
driver.quit()
반응형

댓글