다음 동적 웹 테이블이 있습니다.
(checkbox) ID_No country_code Date Time FileName
1A 5J 10/04/2019 12:05:45 filename_12:05
1A 5J 10/04/2019 13:05:45 filename2
3A 8J 10/03/2019 14:05:45 filename2
4A 9J 10/04/2019 14:08:45 filename1
id_no의 왼쪽에는 확인란이 있습니다.
다음 데이터 프레임이 있습니다.
ID_No country_code Date Time FileName
1A 5J 10/04/2019
1A 5J 10/04/2019
데이터 프레임에서 일치하는 country_code, ID_No 및 Date에 해당하는 동적 웹 테이블의 행만 확인하고 데이터 프레임에 시간 및 파일 이름 값을 채우고 싶습니다.
한 번에 하나의 확인란을 선택하는 루프에서 아래 코드를 작성하고 있습니다.
for index,row in df.iterrows():
id_no=row['ID_No']
country_code=row['country_code']
date=row['Date']
driver = webdriver.Chrome()
driver.get(website_URL)
driver.find_element_by_xpath("//tr[td[contains(text(),date)] and
td[contains(text(),country_code)] and td[contains(text(),id_no)] ]//input").click()
이 경우 Chrome 콘솔에서이 xpath를 사용할 때 country_code = '5J'및 ID_No = '1A'및 Date = '10 / 04 / 2019 ':
$x("//tr[td[contains(text(),'10/04/2019')] and
td[contains(text(),'5J')] and td[contains(text(),'1A')] ]")[0]
위의 조건을 충족하는 첫 번째 행이 포함되어 있습니다.이 웹 테이블의 행에 대해 다음 HTML을 얻습니다.
<tr class="class1">
<td width="2%"> </td> <!–– checkbox ––>
<td width="2%"> 1A </td>
<td width="2%"> 5J </td>
<td width="2%"> 10/04/2019 </td>
<td width="2%"> 12:05:45 </td>
<td width="2%"> filename_12:05 </td>
</tr>
선택한 확인란에 해당하는 동적 웹 테이블에서 해당 파일 이름과 시간을 어떻게 추출 할 수 있습니까?
위의 경우 첫 번째 반복에서 extracted_filename='filename_12:05' and time='12:05:45'
second_iteration,extracted_filename='filename2' and time='13:05:45
이 xpaths를 시도하고 어떻게 진행되는지 알려주십시오.
이것은 당신에게 일치하는 행의 시간을 줄 것입니다
time= driver.find_element_by_xpath("//tr[td[contains(text(),date)] and td[contains(text(),country_code)] and td[contains(text(),id_no)] ]//input/../following-sibling::td[4]").text
일치하는 행의 파일 이름을 제공합니다.
filename=driver.find_element_by_xpath("//tr[td[contains(text(),date)] and td[contains(text(),country_code)] and td[contains(text(),id_no)]]//input/../following-sibling::td[5]").text
코드로 :
for index,row in df.iterrows():
id_no=row['ID_No']
country_code=row['country_code']
date=row['Date']
driver = webdriver.Chrome()
driver.get(website_URL)
driver.find_element_by_xpath("//tr[td[contains(text(),date)] and td[contains(text(),country_code)] and td[contains(text(),id_no)] ]//input").click()
time= driver.find_element_by_xpath("//tr[td[contains(text(),date)] and td[contains(text(),country_code)] and td[contains(text(),id_no)] ]//input/../following-sibling::td[4]").text
filename=driver.find_element_by_xpath("//tr[td[contains(text(),date)] and td[contains(text(),country_code)] and td[contains(text(),id_no)]]//input/../following-sibling::td[5]").text
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다