Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Selenium按列名复制表列_Python_Selenium_Xpath - Fatal编程技术网

Python Selenium按列名复制表列

Python Selenium按列名复制表列,python,selenium,xpath,Python,Selenium,Xpath,我有一个表,它有如下标题: 如何使用xpath选择整个列以存储在数组中。 我希望使用不同的阵列,例如: courses = [] teacher = [] avg = [] 请记住,这些列没有任何ID或类,因此我需要一种只使用列名称进行选择的方法 以下是表格的代码: <table border="0"> <tbody> <tr> <td nowrap="nowrap">Courses</td> <td nowrap="nowra

我有一个表,它有如下标题:

如何使用xpath选择整个列以存储在数组中。 我希望使用不同的阵列,例如:

courses = []
teacher = []
avg = []
请记住,这些列没有任何ID或类,因此我需要一种只使用列名称进行选择的方法

以下是表格的代码:

<table border="0">
<tbody>
<tr>
<td nowrap="nowrap">Courses</td>
<td nowrap="nowrap">Teacher</td>
<td><select name="fldMarkingPeriod" onchange="switchMarkingPeriod(this.value);">
<option value="MP1">MP1</option>
<option selected="selected" value="MP2">MP2</option>
<option value="MP3">MP3</option>
</select>Avg</td>
</tr>
<tr>
<td nowrap="nowrap">[Course Name]</td>
<td nowrap="nowrap">[Teacher Name]</td>
<td>
<table width="100%" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td title="View Course Summary" width="70%">100%</td>
<td width="30%">A+</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td nowrap="nowrap">[Course Name]</td>
<td nowrap="nowrap">[Teacher Name]</td>
<td>
<table width="100%" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td title="View Course Summary" width="70%">100%</td>
<td width="30%">A+</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td nowrap="nowrap">[Course Name]</td>
<td nowrap="nowrap">[Teacher Name]</td>
<td>
<table width="100%" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td title="View Course Summary" width="70%">100%</td>
<td width="30%">A+</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>

课程
老师
MP1
MP2
MP3
平均值
[课程名称]
[教师姓名]
100%
A+
[课程名称]
[教师姓名]
100%
A+
[课程名称]
[教师姓名]
100%
A+

有什么想法吗?谢谢。

我不清楚为什么需要按列显示数据,但下面是一个示例实现:

courses = []
teachers = []
avgs = []

for row in table.find_elements_by_css("table > tbody > tr")[1:]:
    course, teacher, _, avg = [td.text for td in row.find_elements_by_xpath(".//td")]

    courses.append(course)
    teachers.append(teacher)
    avgs.append(avg)

如果没有表格的HTML代码,就不可能提供一个好的答案。@alecxe在这里,但我确实删除了一些个人和额外的信息,并对其进行了一些清理。希望这将有助于给出一个错误:ValueError:需要超过1个值才能解包。这是代码吗?我还将文本中的第4行更改为“驱动程序。通过\u css\u选择器查找\u元素”,但它仍然给了我相同的错误…很抱歉这么晚才回复,但仍然是相同的错误。。。仍然不知道如何修复。。。