docker로 크롤링 실행

docker로 크롤링 실행
Photo by Rubaitul Azad / Unsplash

docker file

FROM python:3.11.4
#FROM python:3.8.8
WORKDIR /root
RUN apt-get update 
# install google chrome
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
RUN apt-get -y update
RUN apt-get install -y google-chrome-stable

# install chromedriver
RUN apt-get install wget
RUN apt-get install -yqq unzip
#RUN wget -O /tmp/chromedriver.zip http://chromedriver.storage.googleapis.com/`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`/chromedriver_linux64.zip
RUN wget -O /tmp/chromedriver.zip https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/116.0.5845.96/linux64/chromedriver-linux64.zip
#RUN unzip /tmp/chromedriver.zip chromedriver -d /usr/local/bin/
RUN unzip /tmp/chromedriver.zip chromedriver-linux64/chromedriver -d /usr/local/bin/
# set display port to avoid crash
ENV DISPLAY=:99

# install selenium
RUN pip install selenium==4.12.0

RUN pip install webdriver_manager

RUN apt-get update 
ADD test.py .
CMD ["python3", "test.py"]

test.py

from selenium import webdriver
from selenium.webdriver.common.by import By
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--window-size=1920,1080')
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
driver = webdriver.Chrome(options=chrome_options)
print("process1")
URL ='https://www.google.co.kr/imghp'
driver.get(url=URL)
print("process3")
driver.implicitly_wait(time_to_wait=10)
print("process4")
screenshot = driver.save_screenshot('test.png')
print("process4")
elem = driver.find_element(By.CSS_SELECTOR,"#APjFqb")
driver.quit()
print("Success")


'''
from webdriver_manager.chrome import ChromeDriverManager
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service



print("process1")

#driver = webdriver.Chrome()
'''
'''
service = Service(executable_path='/usr/lib/chromium-browser/chromedriver')
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(service=service, options=options)



chrome_options = webdriver.ChromeOptions()

chrome_options.add_argument('--headless')

chrome_options.add_argument('--no-sandbox')

chrome_options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome(executable_path="/home/streamsets/crawlingExe/chromedriver",chrome_options=chrome_options)


option = webdriver.ChromeOptions()
driver = webdriver.Chrome(options = option)
'''


'''
print("process1")
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--window-size=1920,1080')
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
driver = webdriver.Chrome(options=chrome_options)

print("process2")
URL ='https://www.google.co.kr/imghp'
driver.get(url=URL)
print("process3")
driver.implicitly_wait(time_to_wait=10)
print("process4")


elem = driver.find_element(By.CSS_SELECTOR,"#APjFqb")

print("Success")



driver.quit()
'''

All versions of selenium-webdriver | RubyGems.org | your community gem host
Which ChromeDriver version is compatible with which Chrome Browser version?
Actually I’m a bit confused. Although I read several resources about this. For having a test of Selenium 3 using ChromeBrowser we need an extra app called ChromeDriver. I found this text from Git…
Docker
How To Run Selenium With Chrome In Docker
I installed google-chrome in a Docker, but when I run my Python 2 script of Selenium, it failed like this: automation@1c17781fef0c:/topology-editor/test$ python test.pyTraceback (most recent call…
TypeError: WebDriver.__init__() got an unexpected keyword argument ‘executable_path’ in Selenium Python
My code:from selenium import webdriverfrom selenium.webdriver.chrome.options import Options option = webdriver.ChromeOptions()driver = webdriver.Chrome(executable_path=‘./chromedriver.exe’, opt…
Where does chromedriver install to?
I’ve executed sudo apt-get install chromium-chromedriver for selenium, but which chromedriver does not return anything.
Docker
How To Run Selenium With Chrome In Docker
I installed google-chrome in a Docker, but when I run my Python 2 script of Selenium, it failed like this: automation@1c17781fef0c:/topology-editor/test$ python test.pyTraceback (most recent call…
[에러] Docker & ChromeDriver path
다음과 같은 에러가 발생하였다.chrome driver의 경로를 찾을 수 없다는 데, 분명 저 위치에 잘만 설치했는데, 왜 못 찾는지 이해를 할 수가 없었다.내가 생각하지 못했던 부분은 였다.그러니까 도커에서 Selenium이 실행되기 때문에 당연히 외부에 설치되어있는
Dockerfile 로 간단한 python 실행파일 이미지 만들기
간단한 python 실행파일 이미지를 만들어보자
파이썬을 위한 Dockerfile 작성하기
Docker가 처음이라면, 이전 포스팅을 참고하시기 바랍니다. Docker 간편한 설치부터 실행까지 Docker, DockerHub 명령어 정리 파이썬을 위한 Dockerfile 작성하기 Flask Application Dockerfile은 일종의 이미지 설정파일입니다. 명령어를 통해 이미지를 생성할 수 있습니다.파이썬 웹 어플리케이션을 Docker로 실행시키는 예제를 통해 천천히 정리해보겠습니다. 먼저 위와 같이 간단한 플라스크 웹 어플리케이션을 작성합니다.필요한 패키지는 requirements.txt…