행위

"Selenium"의 두 판 사이의 차이

DB CAFE

(셀레니엄 자동화)
 
(같은 사용자의 중간 판 하나는 보이지 않습니다)
2번째 줄: 2번째 줄:
  
 
https://www.youtube.com/watch?v=vK_oJR_6QFc
 
https://www.youtube.com/watch?v=vK_oJR_6QFc
 +
 +
<source lang=python>
 +
from selenium import webdriver
 +
from bs4 import BeautifulSoup
 +
 +
# setup Driver|Chrome : 크롬드라이버를 사용하는 driver 생성
 +
driver = webdriver.Chrome('/Users/beomi/Downloads/chromedriver')
 +
driver.implicitly_wait(3) # 암묵적으로 웹 자원을 (최대) 3초 기다리기
 +
# Login
 +
driver.get('https://nid.naver.com/nidlogin.login') # 네이버 로그인 URL로 이동하기
 +
driver.find_element_by_name('id').send_keys('naver_id') # 값 입력
 +
driver.find_element_by_name('pw').send_keys('mypassword1234')
 +
driver.find_element_by_xpath(
 +
    '//*[@id="frmNIDLogin"]/fieldset/input'
 +
).click() # 버튼클릭하기
 +
driver.get('https://order.pay.naver.com/home') # Naver 페이 들어가기
 +
html = driver.page_source # 페이지의 elements모두 가져오기
 +
soup = BeautifulSoup(html, 'html.parser') # BeautifulSoup사용하기
 +
notices = soup.select('div.p_inr > div.p_info > a > span')
 +
 +
for n in notices:
 +
    print(n.text.strip())
 +
</source>
 +
 +
[[category:python]]

2020년 4월 27일 (월) 15:16 기준 최신판

thumb_up 추천메뉴 바로가기


셀레니엄 자동화[편집]

https://www.youtube.com/watch?v=vK_oJR_6QFc

from selenium import webdriver
from bs4 import BeautifulSoup

# setup Driver|Chrome : 크롬드라이버를 사용하는 driver 생성
driver = webdriver.Chrome('/Users/beomi/Downloads/chromedriver')
driver.implicitly_wait(3) # 암묵적으로 웹 자원을 (최대) 3초 기다리기
# Login
driver.get('https://nid.naver.com/nidlogin.login') # 네이버 로그인 URL로 이동하기
driver.find_element_by_name('id').send_keys('naver_id') # 값 입력
driver.find_element_by_name('pw').send_keys('mypassword1234')
driver.find_element_by_xpath(
    '//*[@id="frmNIDLogin"]/fieldset/input'
).click() # 버튼클릭하기
driver.get('https://order.pay.naver.com/home') # Naver 페이 들어가기
html = driver.page_source # 페이지의 elements모두 가져오기
soup = BeautifulSoup(html, 'html.parser') # BeautifulSoup사용하기
notices = soup.select('div.p_inr > div.p_info > a > span')

for n in notices:
    print(n.text.strip())