¾È±Ô °øºÎ¹æ

Python ÇÁ·Î±×·¡¹Ö > ÀÚµ¿ ·Î±×ÀÎ ±¸ÇöÇϱâ

µî·ÏÀÏ : 2018-07-02 16:04 Á¶È¸¼ö : 53,583

À̹ø Æ÷½ºÆ®´Â ȨÆäÀÌÁöÀÇ ·Î±×ÀÎ ºÎºÐÀ» ÀÚµ¿À¸·Î ·Î±×ÀÎ ÇÏ´Â °£´ÜÇÑ ±â´ÉÀÇ ¸ÞÅ©·Î¸¦ Å×½ºÆ® ÇØ º¸°íÀÚ ÇÕ´Ï´Ù.

¸ÕÀú ·Î±×ÀÎ À¥ÆäÀÌÁöÀÇ ¾ÆÀ̵ð/Æнº¿öµå¸¦ ÀԷ¹޴ input °´Ã¼¸¦ ã¾Æ¾ß ÇÕ´Ï´Ù.

°´Ã¼¸¦ ã´Â ¹æ¹ýÀº ¾Æ·¡ ±×¸²Ã³·³ ·Î±×ÀÎ °´Ã¼¿¡¼­ ¸¶¿ì½º ¿À¸¥ÂÊ ¹öÆ°À» ´­·¯ °Ë»ç(F12) ¸¦ ¼±ÅÃÇÏ°Ô µÇ¸é °´Ã¼¸¦ ã¾Æ°¥ ¼ö ÀÖ½À´Ï´Ù.



¾Æ·¡ ±×¸²Ã³·³ ¾ÆÀ̵ð ÀÔ·ÂÇÏ´Â ºÎºÐ¿¡ ¸¶¿ì½º °®´Ù ´ë°í ¿À¸¥ÂÊ ¹öÆ°À» ´©¸£¸é ³ª¿À´Â ‘¿ä¼Ò °Ë»ç(Q)’¸¦ ½ÇÇàÇØ ÁÝ´Ï´Ù.

À¥ÆäÀÌÁö HTML °´Ã¼¸¦ º¸¸é ¾Æ·¡ ó·³ µÇ¾î ÀÖ½À´Ï´Ù.
 
<table>
<tr>
	<td><input type="Text" name="m_id" maxlength="14" size="20"></td>
	<td><input type="Text" name="m_passwd" maxlength="14" size="20"></td>
</tr>
<tr>
	<td colspan='2'><span class="btn_b_white01" onclick="fnc_login_regist('frm_login');">·Î±×ÀÎ </span></td>
</tr>
</table>
¾ÆÀ̵ð : m_id
Æнº¿öµå : m_passwd
·Î±×ÀιöÆ° Ŭ¸¯ : fnc_login_regist('frm_login');

À§¿Í °°ÀÌ ÀÌ·ç¾î Á® ÀÖÀ½À» ¾Ë ¼ö ÀÖ½À´Ï´Ù.

À§ 3°³ÀÇ °´Ã¼¿¡ °ªÀ» ³Ö°í ½ÇÇàÇÏ´Â ¹æ¹ýÀº ¾Æ·¡¿Í °°½À´Ï´Ù.

   WebDriverWait(driver, WAITTIME).until(EC.presence_of_element_located((By.XPATH, "//td/input[@name='m_id']"))).send_keys(USERID)
   driver.find_element_by_xpath("//td/input[@name='m_passwd']").send_keys(PASSWORD)
   driver.execute_script("JavaScript:fnc_login_regist('frm_login')")


¿©±â±îÁö ÇÑ ÈÄ ´Ù½Ã ½ºÅ©¸³Æ®¸¦ ½ÇÇàÇØ º¸¸é ¾ÆÀ̵ð/Æнº¿öµå°¡ Àß ÀԷµǰí ÀÖ´Â °É È®ÀÎÇÒ ¼ö Àֳ׿ä.

¼¼¹ø° ÁÙ¿¡´Â À¥ÆäÀÌÁö ½ºÅ©¸³Æ®¸¦ ½ÇÇàÇÏ´Â ¸í·ÉÀÔ´Ï´Ù.

driver.execute_script("JavaScript:fnc_login_regist()")
 

XPATH

XPATH·Î À§¿¡ ÇÏÀ̶óÀÌÆ® µÇ¾î ÀÖ´Â ¼Ò½ºÀÇ <input ~ name=”m_id”>¸¦ ¼±ÅÃÇÏ·Á¸é “//input[@name=’m_id’]” °¡ µË´Ï´Ù. ¸¸¾à nameÀÌ id°¡ ¾Æ´Ï¶ó m_passwd ¿´´Ù¸é “//input[@name=’m_passwd’]”°¡ µÇ°ÚÁÒ.

¶ÇÇÑ inputÀÌ ¾Æ´Ï¶ó <img ~ src=”a.gif”> ¶ó¸é “//img[@src=’a.gif’]”¶ó°í ÇÏ¸é µË´Ï´Ù.

Áï, // ·Î ½ÃÀÛÇؼ­ ãÀ¸·Á´Â ÅÂ±× À̸§À» Àû¾îÁÖ°í [] ¾È¿¡ Ãß°¡·Î ãÀ» ÇØ´ç ű×ÀÇ ¼Ó¼ºÀ» Àû¾îÁÖ¸é µË´Ï´Ù.
¼Ó¼ºÀº ¿©·¯°³¸¦ ³ÖÀ» ¼ö Àִµ¥ <input name=”id”, id=”id”, class=”button”> À» ã°í ½ÍÀ¸¸é “//input[@name=’id’][@id=’id’][@class=’button’]” À̶ó°í ÇÏ¸é µË´Ï´Ù.

ÁÖÀÇÇÒ Á¡ÀÌ ÀÌ ¹æ¹ýÀº Á¶°Ç¿¡ ÇØ´ç ÇÏ´Â ¸ðµç °´Ã¼¸¦ ãÀ¸¹Ç·Î °á°ú°¡ ÇÑ °³°¡ ¾Æ´Ò ¼öµµ ÀÖ½À´Ï´Ù. ¾Æ·¡¿Í °°Àº ű׵éÀÌ ÀÖ´Ù°í ÇսôÙ.

1. <input class=”button” name=”id” type=”text” />
2. <input class=”button” name=”password” type=”text” />
3. <input name=”id” type=”text” />

 

¿©±â¼­ “//input” À» ãÀ¸¸é 3°³°¡ ´Ù ³ª¿À°í,

“//input[@name=’id’]” ´Â 1, 3 ¹ø

“//input[@class=’button’]” Àº 1, 2 ¹ø

“//input[@name=’id’][@class=’button’]” À» ÇØ¾ß 1¹ø¸¸ ³ª¿À°Ô µË´Ï´Ù.

 

¾Æ·¡¿Í °°Àº ¿¹µµ »ìÆ캾½Ã´Ù.

1. <td><input name=”id”></td>

2. <form><input name=”id”></form>

ÀÌ °æ¿ì “//input[@name=’id’]”·Î ã°Ô µÇ¸é 1, 2¹øÀÌ ¸ðµÎ ³ª¿É´Ï´Ù. ÀÌ ¶§ 1¹ø¸¸ ã°í ½ÍÀ¸¸é “//td/input[@name=’id’]”¿Í °°ÀÌ ÇÏ¸é µË´Ï´Ù. Áï ‘/’ ´Â °èÃþ±¸Á¶¸¦ ³ªÅ¸³À´Ï´Ù. ÀÌó·³ ãÀ¸·Á´Â °´Ã¼ ÁÖº¯ÀÇ Å±׵éÀÇ ±¸Á¶¿Í °¢ ű×ÀÇ ¼Ó¼ºÀ» È°¿ëÇØ Ã£À¸¸é µË´Ï´Ù.

À§ÀÇ ¼Ò½º¸¦ ¾Æ·¡¿¡ ÷ºÎÇÕ´Ï´Ù. ÇÊ¿äÇϽźÐÀº ºÐ¼®ÈÄ Å×½ºÆ®ÇØ º¸½Ã±â ¹Ù¶ø´Ï´Ù.

°¨»çÇÕ´Ï´Ù.
 

#-*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
import sys

HOME_URL = "http://water.entersoft.kr/include/asp/login_water.asp"
USERID = "test"
PASSWORD = "test"

WAITTIME = 50000
SLEEPSEC = 5

def fnc_login(driver):
    print("·Î±×ÀΠó¸®1")
    WebDriverWait(driver, WAITTIME).until(EC.presence_of_element_located((By.XPATH, "//td/input[@name='m_id']"))).send_keys(USERID)
    time.sleep(2)
    driver.find_element_by_xpath("//td/input[@name='m_passwd']").send_keys(PASSWORD)
    time.sleep(2)
    driver.execute_script("JavaScript:fnc_login_regist('frm_login')")

if __name__ == "__main__":
    driver = webdriver.Chrome('./chromedriver')
    driver.set_window_size(800,800)
    driver.implicitly_wait(5)
    driver.get(HOME_URL)
    fnc_login(driver)

 CSS °´Ã¼¸¦ ã¾Æ ¹öÆ°À» Ŭ¸¯ÇÏ´Â ¿¹Á¦´Â ¾Æ·¡¿Í °°½À´Ï´Ù.
 
menus = driver.find_elements_by_css_selector('.btn_global')          # btn_global °´Ã¼¸¦ ã´Â´Ù.
pypi = None
 
for m in menus:
         pypi = m

pypi.click()  # pypi °´Ã¼¸¦ Ŭ¸¯ÇÑ´Ù.

time.sleep(5)  # 5ÃÊ ´ë±â
driver.quit()  # ºê¶ó¿ìÀú Á¾·á
¡Ø Ȥ½Ã µµ¿òÀÌ µÇ¼Ì´Ù¸é ´ñ±Û¿¡ ÇѸ¶µð ³²°ÜÁÖ¼¼¿ä!
ÀÛ¼ºÀÚ   ºñ¹Ð¹øÈ£
ÀÚµ¿±Û ¹æÁö     (ÀÚµ¿±Û ¹æÁö ±â´ÉÀÔ´Ï´Ù.)
³»¿ë   ´ñ±Û´Þ±â 
À̸ÞÀÏ ¹®ÀÇ : cak0280@nate.com  
Copyright 2000 By ENTERSOFT.KR All Rights Reserved.