다음과 같은 웹 페이지가 있습니다.
<table class="data" width="100%" cellpadding="0" cellspacing="0">
<tbody><tr>
<th>1</th>
<th>2</th>
<th>3 by</th>
</tr>
<tr> <td width="10%"><a href="foo1">5120432</a></td>
<td width="70%">INTERESTED_SITE1/</td>
<td width="20%"><a href="foo2">foo2</a></td>
</tr>
<tr class="alt"> <td width="10%"><a href="foo1">5120431</a></td>
<td width="70%">INTERESTED_SITE2</td>
<td width="20%"><a href="foo2">foo2</a></td>
</tr>
2 개의 사이트 (interested_site1 및 Interested_site2)를 어딘가에 배치하고 싶습니다. 나는 다음과 같이 시도했다.
chrome = webdriver.Chrome(chrome_path)
chrome.get("fooSite")
time.sleep(.5)
alert = chrome.find_element_by_xpath("/div/table/tbody/tr[2]/td[2]").text
print (alert)
하지만 첫 번째 사이트를 찾을 수 없습니다. for-loop에서 이것을 할 수 없다면 모든 링크를 개별적으로 가져와도 괜찮습니다. 그 링크에 어떻게 갈 수 있습니까?
CSS 쿼리를 사용하는 것이 더 쉬울 것입니다.
driver.find_element_by_css_selector("td:nth-child(2)")
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다