살콤아내 자기계발/파이썬

파이썬으로 배우는 웹 크롤러 3주차_Selenium

살콤아내 2021. 6. 23. 12:51
728x90
반응형

Selenium 설치

 

Step 1: Chrome >> 더보기 >> 도움말 >> Chrome 정보에서 버전확인 후 ChromeDriver 설치

Step 2: Anaconda Prompt >> pip install selenium 입력 후 selenium 설치

Step 3: Anaconda Spyder에서 ChromeDriver.exe 경로설정 후 실행하면 3줄에 입력된 url 창이 뜬다

 

https://chromedriver.chromium.org/downloads

 

ChromeDriver - WebDriver for Chrome - Downloads

Current Releases If you are using Chrome version 92, please download ChromeDriver 92.0.4515.43 If you are using Chrome version 91, please download ChromeDriver 91.0.4472.101 If you are using Chrome version 90, please download ChromeDriver 90.0.4430.24 If y

chromedriver.chromium.org

 

python-crawler-book-mastser_1_selenium.py
0.02MB

 

 

 

python-crawler-book-master 8.3~ 참고

 

BeautifulSoup은 파싱한 웹을 bs객체에 담았다 >> bs=BeautifulSoup (A, parser)

Selenium은 driver.get(url)은 ulr에 직접 접속을 한 것으로 BeautifulSoup과 차이가 있다. 

 

 

Selenium의 특징

1. 웹페이지>>F12>> Copy>>full XPath

특정 id, tag, class 등을 찾을 때  를 누르면 해당 코드 (웹페이지 전체경로)를 아래와 같이 따올 수 있다.

/html/body/header/div

 

2. 웹브라우저를 열어서 클릭, 타이핑 등을 할 수 있다.

더보기나 다른 웹페이지로 이동해야 보이는 html 코드들도 있다. bs는 활성화되지 않은 html 코드를 볼 수 없지만 selenium은 가능하다. (명령어를 내려서 이러한 기능을 사용할 수 있다) 

728x90
반응형