如何使用硒python读表数据? [英] How to read table data using selenium python?
问题描述
以下是表格中的HTML源代码,它似乎对于硒的内容非常复杂。有人可以帮助我,使用硒将这些数据读入python?
< div class =general_table>
< div class =general_s>
< div class =general_text1>名称< / div>
< div class =general_text2> Abhishek< / div>
< / div>
< div class =general_m>
< div class =general_text1>姓氏< / div>
< div class =general_text2> Kulkarni< / div>
< / div>
< div class =general_s>
< div class =general_text1>手机< / div>
< div class =general_text2> 13613123< / DIV>
< / div>
< div class =general_m>
< div class =general_text1>手机< / div>
< div class =general_text2> 82928091< / div>
< / div>
< div class =general_s>
< div class =general_text1>城市< / div>
< div class =general_text2>< / div>
< / div>
< div class =general_m>
< div class =general_text1> Model< / div>
< div class =general_text2> DELL PERC H700< / div>
< / div>
< / div>
使用selenium webdriver读取此表,xpath似乎是简单的方法 -
我不太了解python,所以代码可能是错的,但这个想法似乎是正确的 -
要找出 general_table
中div标签的数量,我们使用xpath -
然后,您可以使用循环遍历每个元素 - 您可以通过这种方式读取表格中的所有标签。 Following is the table HTML source which seems to be very complex for selenium to read its contents.. Can somebody help me, reading this data into python using selenium?
To read this table using selenium webdriver, xpath seems to be the easy way - I'm do not know python properly so the code might be wrong but the idea seems to be right - To find out the number of div tags with in the Then you can loop through each of the elements using a loop - You can read all the tags in the table by this way. 这篇关于如何使用硒python读表数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! driver.find_elements_by_xpath((// * [@ class ='general_table'] / div)
这将返回一个带 size - strong>。
for(int i = 1; i <= list.length; i ++){
String text1 = driver.find_element_by_xpath(// * [@ class ='general_table'] / div [+ i +] / div [1])。text;
String text2 = driver.find_element_by_xpath(// * [@ class ='general_table'] / div [+ i +] / div [2] ).text;
}
<div class="general_table">
<div class="general_s">
<div class="general_text1">Name</div>
<div class="general_text2">Abhishek</div>
</div>
<div class="general_m">
<div class="general_text1">Last Name</div>
<div class="general_text2">Kulkarni</div>
</div>
<div class="general_s">
<div class="general_text1">Phone</div>
<div class="general_text2"> 13613123</div>
</div>
<div class="general_m">
<div class="general_text1">Cell Phone</div>
<div class="general_text2">82928091</div>
</div>
<div class="general_s">
<div class="general_text1">City</div>
<div class="general_text2"></div>
</div>
<div class="general_m">
<div class="general_text1">Model</div>
<div class="general_text2"> DELL PERC H700</div>
</div>
</div>
general_table
we use the xpath - driver.find_elements_by_xpath(("//*[@class='general_table']/div")
which will return a List with size - 6.for(int i=1;i<=list.length;i++){
String text1 = driver.find_element_by_xpath("//*[@class='general_table']/div["+i+"]/div[1]").text;
String text2 = driver.find_element_by_xpath("//*[@class='general_table']/div["+i+"]/div[2]").text;
}