我想使用硒webdriver(Firefox)从网站获取有关大学课程的信息,我们可以看到课程评论....我可以让webdriver成功登录到该网站,并进入课程信息页面,但一旦我在那里,我不能访问整体课程评分的文本元素。使用硒webdriver python来检索SVG文本元素
这里是页面的样子:
对课程的评分表:
这是文本元素的HTML代码如下所示:
<text style="text-anchor: middle; font: 12px Arial,Helvetica,sans-serif;
opacity: 1;" x="438.00500259399416" y="131.25" text-anchor="middle"
font="10px "Arial"" stroke="none" fill="#3c4c30" font-size="12px"
font-family="Arial,Helvetica,sans-serif" font-style="normal" font-
weight="normal" transform="matrix(1,0,0,1,0,0)" opacity="1"><tspan
dy="4">3.00</tspan></text>
而svg代码:
<svg height="200" version="1.1" width="600"
xmlns="http://www.w3.org/2000/svg" style="overflow: hidden; position:
relative; left: -0.5px; top: -0.866669px;"><rect x="0" y="0" width="600"
height="200" r="0" rx="0" ry="0" fill="#ffffff" stroke="#ffffff"
style="stroke-linejoin: round; stroke-linecap: square; stroke-opacity: 1;
fill-opacity: 1;" stroke-linejoin="round" stroke-linecap="square" stroke-
width="1" stroke-opacity="1" fill-opacity="1"></rect>
.......</svg>
首先,我尝试通过它的CSS选择器来识别元素(#chart> svg:nth-child(1)> text:nth-child(107)),但是我得到了一个nosuchelement异常。
我认为下一个选项是通过XPath查找元素,但我不确定如何识别“3.00”元素,因为它没有特定的ID或类名称。
父元素1: (栏和文本文件/习题集) -Papers/Pset中标签:
<text style="text-anchor: middle; font: 12px Arial,Helvetica,sans-serif;"
x="0" y="0" text-anchor="middle" font="10px "Arial"" stroke="none"
fill="#3c4c30" font-size="12px" font-family="Arial,Helvetica,sans-serif"
font-style="normal" font-weight="normal"
transform="matrix(1,0,0,1,128,102.0833)"><tspan dy="4">Papers, Reports,
Problem Sets, Examinations</tspan></text>
纸张/ Pset中吧:
<rect x="262.03334045410156" y="96.00694444444444" width="216.0105950756073"
height="12.152777777777777" r="0" rx="0" ry="0" fill="#ffffff"
stroke="#ffffff" style="stroke-linejoin: round; stroke-linecap: square;
stroke-opacity: 0; opacity: 1; fill-opacity: 0;" stroke-linejoin="round"
stroke-linecap="square" stroke-width="0" stroke-opacity="0" opacity="1"
fill-opacity="0"></rect>
号码评级纸/ pset中:
<text style="text-anchor: middle; font: 12px Arial,Helvetica,sans-serif;
opacity: 1;" x="458.2356021327972" y="102.08333333333333" text-
anchor="middle" font="10px "Arial"" stroke="none" fill="#3c4c30"
font-size="12px" font-family="Arial,Helvetica,sans-serif" font-
style="normal" font-weight="normal" transform="matrix(1,0,0,1,0,0)"
opacity="1"><tspan dy="3.999997456868485">3.31</tspan></text>
父元素2(对其他学生的反馈小号吧)
反馈文本标签:
<text style="text-anchor: middle; font: 12px Arial,Helvetica,sans-serif;"
x="0" y="0" text-anchor="middle" font="10px "Arial"" stroke="none"
fill="#3c4c30" font-size="12px" font-family="Arial,Helvetica,sans-serif"
font-style="normal" font-weight="normal"
transform="matrix(1,0,0,1,175.3333,160.4167)"><tspan dy="4">Feedback for
other students</tspan></text>
酒吧反馈:
<rect x="262.03334045410156" y="154.34027777777777"
width="232.3255947036743" height="12.152777777777777" r="0" rx="0" ry="0"
fill="#ffffff" stroke="#ffffff" style="stroke-linejoin: round; stroke-
linecap: square; stroke-opacity: 0; opacity: 1; fill-opacity: 0;" stroke-
linejoin="round" stroke-linecap="square" stroke-width="0" stroke-opacity="0"
opacity="1" fill-opacity="0"></rect>
反馈评价文本:
<text style="text-anchor: middle; font: 12px Arial,Helvetica,sans-serif;
opacity: 1;" x="474.55060176086425" y="160.41666666666666" text-
anchor="middle" font="10px "Arial"" stroke="none" fill="#3c4c30"
font-size="12px" font-family="Arial,Helvetica,sans-serif" font-
style="normal" font-weight="normal" transform="matrix(1,0,0,1,0,0)"
opacity="1"><tspan dy="3.9999949137369697">3.56</tspan></text>
这里是身体的整个HTML代码来自page_source的网站:
(https://pastebin.com/zpd4iF05)
而对于Python代码我试图用找到的元素:
(https://pastebin.com/aW40P86u)
AHHH是它的工作!!!!!!!我只需要将地图类型转换为列表使用 lis =列表(值) 谢谢吨!不够感谢你! – programmingnovice