๋ฐ์ํ
Selenium library: ์น ํฌ๋กค๋ง ํ์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ Keys ๋ชจ๋ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ
ํค๋ณด๋์ ํค๋ฅผ ์ปดํจํฐ์ ์ ๋ฌํ๊ธฐ ์ํด์ ์ฌ์ฉํจ
send_keys( ์ ๋ ฅํ ํค)
from selenium.webdriver.common.keys import Keys
์ ๋ ฅํ ํค ๋ชฉ๋ก:์ ๋ ฅํ ํค
Kyes.ENTER,
Keys.ARROW_DOWN,
Keys.ARROW_LEFT,
Keys.ARROW_RIGHT,
Keys.ARROW_UP,
Keys.BACK_SPACE,
Keys.CONTROL,
Keys.ALT,
Keys.DELETE,
Keys.TAB,
Keys.SPACE,
Keys.SHIFT,
Keys.EQUALS,
Keys.ESCAPE,
Keys.HOME,
Keys.INSERT,
Keys.PAGE_UP,
Keys.PAGE_DOWN,
Keys.F1, Keys.F2, Keys.F3, Keys.F4, Keys.F5, Keys.F6, Keys.F7,Keys.F8, Keys.F9 Keys.F10,
Keys.F11, Keys.F12
์ํฐ๋ฅผ ๋ณด๋ด๊ณ ์ถ์ ๊ฒฝ์ฐ
send_key(Keys.ENTER)
# ์ ๊น์ ์ฌ์ฉ์
driver=webdriver.Chrome("chromedriver")
driver.get("http://naver.com")
time.sleep(1)
element = driver.find_element_by_id('query')
element.send_keys("์๋์ฐจ")
element.submit()
์ํฐ๋ send_keys() ๋ฉ์๋๋ฅผ ์ด์ฉํด์ ์ํฐํค ๊ฐ์ ์ ๋ฌํ๋ ๋ฐฉ๋ฒ์ธ๋ฐ, ๋ง์ฐ์ค ํด๋ฆญ๊ณผ ๋์ผํ ํจ๊ณผ๋ฅผ ๋ผ ์ ์์.
์คํฌ๋กค๋ฐ ๋ด๋ฆฌ๋ ๋ชจ๋
Keys ๊ฐ์ฒด์์ ARROW_DOWN ์ด๋ผ๋ ์์ฑ์ ์ฌ์ฉํ๋๋ก ํจ.
์๋ ๋ฐฉํฅํค๋ฅผ ๋ํ๋ด๋ ๊ฐ.
์ฐ์ ํ์ด์ง์ html ํ๊ทธ๋ฅผ ํฌ์ปค์ค๋ก ์ก๊ณ send_keys๋ฅผ ์ด์ฉํด์ ๋ฐฉํฅํค๋ฅผ ์ ๋ฌํ๋ฉด ๊ธฐ๋ณธ์ ์ธ ์คํฌ๋กค์ด ๊ฐ๋ฅ
sc_dw = driver.find_element_by_tag_name('html')
for i in range(20):
sc_dw.send_keys(Keys.ARROW_DOWN)
ํค์๋
selenium.webdriver.common.keys / ARROW_DOWN / send_keys()
๋ฐ์ํ
'๐๏ธ์ํํธ์จ์ด > ๐ปpython' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
python ์ฝ๋ ์๊ฐ ๊ณ์ฐ (0) | 2021.11.24 |
---|---|
Kernel died with exit code 1073741845 ์๋ฌ (0) | 2021.11.23 |
[python] crawling customizing (0) | 2021.11.22 |
[git/ source tree] ํ์ ํ ์ฌ์ฉ๋ฒ (0) | 2021.11.21 |
vscode ๋จ ์ฌ์ฉ (0) | 2021.11.16 |