복붙노트

[PYTHON] 파이썬으로 셀렌 웹 드라이버로 텍스트를 얻는 법

PYTHON

파이썬으로 셀렌 웹 드라이버로 텍스트를 얻는 법

난 셀렌 웹 드라이버를 사용하여 텍스트를 얻으려고하고 여기 내 코드입니다. 내 경우에는 ID가 웹 페이지를 다시 시작할 때마다 변경되므로 Xpath를 사용하고 싶지는 않습니다.

내 코드 :

text=driver.find_element_by_class_name("current-stage").getText("my text")

HTML :

<span class="current-text" id="yui_3_7_0_4_1389185744113_384">my text</span>

해결법

  1. ==============================

    1.너는 단지. 텍스트를 원한다.

    너는 단지. 텍스트를 원한다.

    그런 다음 가져온 후에 확인할 수 있습니다. 예상 한대로 전달하지 마십시오.

  2. ==============================

    2.파이썬

    파이썬

    element.text
    

    자바

    element.getText()
    

    기음#

    element.Text
    

    루비

    element.text
    

    예제 (파이썬에서) :

    element=driver.find_element_by_class_name("nameOfClass")
    print(element.text)
    
  3. ==============================

    3.넌 할 수있어,

    넌 할 수있어,

    element = driver.find_element_by_class_name("class_name").text
    

    이렇게하면 텍스트가 반환되고 그 후에 확인됩니다.

  4. ==============================

    4.그것을 발견, 대답은

    그것을 발견, 대답은

    driver.find_element_by_class_name("ctsymbol").text
    
  5. ==============================

    5.감사합니다 이것이 정답 인 것입니다 !!

    감사합니다 이것이 정답 인 것입니다 !!

    from selenium import webdriver
    from selenium.webdriver.support.ui import WebDriverWait
    
    driver = webdriver.Chrome("E:\\Python\\selenium\\webdriver\\chromedriver.exe")
    driver.get("https://www.tatacliq.com/global-desi-navy-embroidered-kurta/p-mp000000000876745")
    driver.set_page_load_timeout(45)
    driver.maximize_window()
    driver.implicitly_wait(2)
    driver.get_screenshot_as_file("E:\\Python\\Tatacliq.png")
    print ("Executed Succesfull")
    driver.find_element_by_xpath("//div[@class='pdp-promo-title pdp-title']").click()`enter code here`
    SpecialPrice =driver.find_element_by_xpath("//div[@class='pdp-promo-title pdp-title']").text
    print(SpecialPrice)
    
  6. from https://stackoverflow.com/questions/20996392/how-to-get-text-with-selenium-web-driver-in-python by cc-by-sa and MIT license