Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- ec2
- SQL
- staging area
- NGINX
- working directory
- AWS
- Wordpress
- docker
- linux
- props
- javascript
- docker-compose
- Selenium
- pagination
- codeigniter4
- react
- centOS7
- Ruby On Rails
- controller
- php
- cron
- Python
- ruby
- dockerfile
- laravel
- imagemagick
- ubuntu
- vue
- MySQL
- Git
Archives
- Today
- Total
내가 한 노력들
[ Linux ] linux환경에서 selenium 사용하기 (ubuntu/centos) 본문
docker 컨테이너를 이용해서 ubuntu 환경을 구축하여, python의 selenium을 사용해볼려고 합니다.
Docker 컨테이너로 ubuntu 컨테이너 생성
docker run -it --name ubuntu-sel ubuntu /bin/bash
package manage 업데이트 및 필요 package 설치
apt update
apt -y install sudo wget unzip vim
linux 용 chrome 설치
cd tmp
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo apt install ./google-chrome-stable_current_amd64.deb
sudo mv /usr/bin/google-chrome-stable /usr/bin/google-chrome
google-chrome –-version
버전을 확인해보니 97버전입니다.
버전이 중요한 이유는 chromedriver를 설치할 때도, 같은 버전을 설치해줘야만 하기 때문입니다.
chromedriver 설치
sudo wget https://chromedriver.storage.googleapis.com/97.0.4692.71/chromedriver_linux64.zip
sudo unzip chromedriver_linux64.zip
sudo mv chromedriver /usr/bin/chromedriver
chromedriver –-version
chromedriver까지 정상적으로 설치가 되었습니다.
pip 설치
apt install python3-pip
selenium을 설치를 위해서 pip를 설치해줍니다.
selenium 설치
pip install selenium
그 외에도 스크래핑에 필요한, beautifulSoup, lxml등은 필요하시면 설치하면 됩니다.
Python 코드 작성
vi main.py
vim에디터를 이용해서 코드를 작성합니다.
main.py
from selenium.webdriver.chrome.options import Options
from selenium import webdriver
options = Options()
options.add_argument("--headless")
options.add_argument("window-size=1400,1500")
options.add_argument("--disable-gpu")
options.add_argument("--no-sandbox")
options.add_argument("start-maximized")
options.add_argument("enable-automation")
options.add_argument("--disable-infobars")
options.add_argument("--disable-dev-shm-usage")
url = "https://www.naver.com/'
browser = webdriver.Chrome(options=options)
browser.get(url)
print(browser.page_source)
headless로 selenium을 동작시켜 네이버 사이트에 있는 html소스 코드를 출력하는 코드입니다.
python 코드 실행
python3 main.py
에러없이, 네이버의 html 코드가 잘 출력되는 것을 확인할 수 있습니다.
'IT 공부 > Linux' 카테고리의 다른 글
[ ubuntu ] 일본어 폰트 패키지 설치 && matplotlib에 적용 (0) | 2022.02.09 |
---|---|
[ Linux ] Cron 사용해서, 일정시간마다 스크립트 실행시키기! (0) | 2022.01.27 |
Centos 환경에서 Nginx 서버 구동하기 (0) | 2021.10.05 |
[ Linux ] Shell Script(4) and Cron(scheduler) (0) | 2021.06.04 |
[ Linux ] Shell script (3) (0) | 2021.06.03 |