반응형
• Headless?
- 창 숨김 모드
- 윈도우 기준 크롬 59, 맥/리눅스 기준 크롬 60버전
- CLI기반의 서버 OS에서도 Selenium을 통한 크롤링 / 테스트를 가능
• Headless 사용
-선언
options.add_argument('headless')
-옵션 지정
options=webdriver.ChromeOptions()
driver=webdriver.Chrome('chromedriver',chrome_options=options)
-> 에러 발생시
driver=webdriver.Chrome('chromedriver',options=options)
from selenium import webdriver
driver = webdriver.Chrome('C:\\chromedriver\\chromedriver')
driver.get('http://naver.com')
driver.implicitly_wait(3)
driver.get_screenshot_as_file('naver_main.png')
driver.quit()
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument('headless')
options.add_argument('window-size=1920x1080')
options.add_argument("disable-gpu")
driver = webdriver.Chrome('C:\\chromedriver\\chromedriver', options=options)
driver.get('http://naver.com')
driver.implicitly_wait(3)
driver.get_screenshot_as_file('naver_main_headless.png')
driver.quit()
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver import ActionChains
options = webdriver.ChromeOptions()
options.add_argument('headless')
driver = webdriver.Chrome('C:\\chromedriver\\chromedriver', options=options)
driver.get('http://pythonscraping.com/pages/files/form.html')
firstnameField = driver.find_element_by_name('firstname')
lastnameField = driver.find_element_by_name('lastname')
submitButton = driver.find_element_by_id('submit')
actions = ActionChains(driver)\
.click(firstnameField).send_keys('An')\
.click(lastnameField).send_keys('Kiwoong')\
.send_keys(Keys.RETURN)
actions.perform()
print(driver.find_element_by_tag_name('body').text)
driver.quit()
반응형
'Python_Crawling > Crawling' 카테고리의 다른 글
[Crawling]imDB(인터넷 영화 데이터 베이스) Tutorial - 1 (0) | 2020.03.29 |
---|---|
[Naver]네이버 메일 제목 가져오기 - 클립보드 사용 (0) | 2020.03.08 |
[Selenium]Python Study - PPT Presentation Material - 2 (0) | 2019.12.18 |
[Selenium]Python Study - PPT Presentation Material - 1 (0) | 2019.12.18 |
[Crawling]Python Study - PPT Presentation Material - 4 (0) | 2019.12.16 |