<html>
<body>
<table style="border:0">
<tbody>
<tr class="">
<td class="pr10">Mon</td>
<td class="pl10">11am – 11pm</td>
</tr>
<tr class="">
<td class="pr10">Tue</td>
<td class="pl10">11am – 11pm</td>
</tr>
<tr class="bold">
<td class="pr10">Wed</td>
<td class="pl10">11am – 11pm</td>
</tr>
<tr class="">
<td class="pr10">Thu</td>
<td class="pl10">11am – 11pm</td>
</tr>
<tr class="">
<td class="pr10">Fri</td>
<td class="pl10">11am – 11pm</td>
</tr>
<tr class="">
<td class="pr10">Sat</td>
<td class="pl10">11am – 11pm</td>
</tr>
<tr class="">
<td class="pr10">Sun</td>
<td class="pl10">11am – 11pm</td>
</tr>
</tbody>
</table>
</html>
</body>
尝试1: driver.find_elements_by_xpath(“ // * [@ class ='pr10']”)
尝试2: driver.find_element_by_xpath(“ // tr [td ='Mon'] / td”)。text
但是它不会获取文本“ Mon”“ 11am-11pm”
text_area = driver.find_elements_by_xpath("//*[@class='pr10']")
for items2 in text_area:
print(items2.text)
答案 0 :(得分:0)
尝试以下方法:
text_area = driver.find_elements_by_xpath("""//*[@id="body"]/table/tbody/tr[1]/td[1]""")
print([elm.get_attribute('innerHTML') for elm in text_area])