2017-12-25 11 views
1

을 감안할 때이 (이하 "절전"방법은 그래서 당신은 내가 찾고 있어요 무엇을 볼 수 있습니다) :파이썬 스플린터 표 조건에 링크를 클릭

from splinter import Browser 
import time 
#from selenium.webdriver.support.ui import WebDriverWait 
#from selenium.webdriver.remote.webdriver import WebDriver 

with Browser() as browser: 
    # Visit URL 
    url = "https://mdoe.state.mi.us/moecs/PublicCredentialSearch.aspx" 
    browser.visit(url) 
    browser.fill('ctl00$ContentPlaceHolder1$txtCredentialNumber', 'IF0000000262422') 

    # Find and click the 'search' button 
    button = browser.find_by_name('ctl00$ContentPlaceHolder1$btnSearch') 
    # Interact with elements 
    button.first.click() 
    #implicitly_wait(time_to_wait=5) 
    time.sleep(30) 

을 내가 스플린터/셀레늄가에있는 링크를 클릭합니다 같은 열의 왼쪽 열에있는 "Professional Teaching Certification Renewal"값에 해당하는 오른쪽 열.

tables=browser.find_by_tag('table') #Get all tables 
rows=tables.find_by_tag('tr') #Get all rows in the tables 
data=rows.find_by_tag('td') #Get the data(cell)s in the rows 

내 전략은 그 대응에 대한 값 (데이터) "전문 교육 인증 갱신"과 함께 행을 찾을 수 있습니다 : 여기

내가 (위의 코드 후) 지금까지 시도했습니다 무엇 행에서 오른쪽 열에있는 링크를 클릭하십시오. 나는 더 나은 전략이 있는지 확실하지 않지만, 만약 그렇다면 확실히 결혼하지 않을 것이다.

데이터 개체를 검사하고 그 개체가 무엇인지 결정하는 방법을 알지 못합니다. 이 작업을 수행 할 수 있다면 나머지 작업을 파악할 수 있습니다.

미리 감사드립니다. 내가 이해, 당신은 사전에 Professional Teaching Certificate Renewal 텍스트를 알고 다음 열의 링크를 찾는 데 사용할 수 있습니다에서, 우리는 첫 번째 텍스트로 td을 찾은 다음 내부 링크를 잡는 next siblingtd 요소로 진행할 수 있기 때문에

답변

1

:

certificate_link = browser.find_by_xpath("//td[. = 'Professional Teaching Certificate Renewal']/following-sibling::td/a") 
certificate_link.first.click() 
+0

놀라운! 나는 그것이 작동하는 방법에 대한 단서가 없다 (여전히 세부 사항에 대해 배우기). 그러나 그것은 매력처럼 작동한다. 많은 감사합니다! –

+0

후속 질문 : https://stackoverflow.com/questions/47974320/python-splinter-get-value-from-table-following-sibling –