본문 바로가기
AI/DataCollecting

[WebCrawling] Selenium

by TSpoons 2024. 8. 19.

https://googlechromelabs.github.io/chrome-for-testing/

 

Chrome for Testing availability

chrome-headless-shellmac-arm64https://storage.googleapis.com/chrome-for-testing-public/127.0.6533.119/mac-arm64/chrome-headless-shell-mac-arm64.zip200

googlechromelabs.github.io

 

chrome 버전과 일치하는지 확인!

 

wget https://storage.googleapis.com/chrome-for-testing-public/127.0.6533.119/linux64/chromedriver-linux64.zip

 

 

cd ~/downloads
unzip chromedriver-linux64.zip
rm chromedriver-linux64.zip

 

- test.py 작성

 

from selenium import webdriver
from selenium.webdriver.chrome.service import Service

driver = webdriver.Chrome(service=Service("/home/tspoon/Downloads/chromedriver-linux64/chromedriver"))

driver.get("https://www.selenium.dev/")

 

 

아마 바로 꺼질 것이다.  python 파일이 한 번 실행되고 나면 스크립트가 종료 되는데 이를 헤결하기 위해 

 

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
import threading
import time

driver = webdriver.Chrome(service=Service("/home/tspoon/Downloads/chromedriver-linux64/chromedriver"))
driver.get("https://www.youtube.com")


def keep_alive():
    while True:
        time.sleep(1)  # 무한 루프로 1초마다 대기


thread = threading.Thread(target=keep_alive)
thread.daemon = True  
thread.start()

try:
    while True:
        time.sleep(1)
except KeyboardInterrupt:
    print("프로그램이 종료되었습니다.")


driver.quit()

 

쓰레드를 이용하자!

'AI > DataCollecting' 카테고리의 다른 글

[Labelme] labelme(라벨링) 사용을 위한 환경 조성  (1) 2024.05.30
[Download] aihub 이용법  (0) 2024.05.23