Ich versuche selen webdriver (Firefox) zu verwenden, um Informationen über College-Kurse von einer Website, wo wir Kursberichte sehen können .... Ich kann den Webdriver, um sich erfolgreich einzuloggen die Website und die Kursinfo-Seite erreichen, aber sobald ich dort bin, kann ich nicht auf das Textelement für die Gesamtbewertung des Kurses zugreifen. Hierselen webdriver python zum Abrufen von SVG-Textelement
ist, was die Seite wie folgt aussieht:
Course Bewertungen Chart:
Und das ist, was das Textelement HTML-Code wie folgt aussieht:
<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>
Und die SVG-Code:
<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>
Zuerst habe ich versucht, das Element mit seinem CSS-Selektor zu identifizieren (#chart> svg: nth-child (1)> text: nth-child (107)), aber ich habe eine nosuchelem-Ausnahme bekommen.
Ich denke, die nächste Option ist, das Element von XPath zu finden, aber ich bin nicht sicher, wie das Element "3.00" zu identifizieren, da es keine bestimmte ID oder Klassenname hat.
Eltern element1: (bar und Text for Papers/Problem-Sets) -Papers/psets Label:
<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>
Papier/psets bar:
<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>
Anzahl Bewertung für Papiere/psets :
Elternelement 2 (Feedback für andere Schüler s bar)
Feedback-Text-Label:
<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>
Bar für Feedback:
<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>
Feedback zur Bewertung Text:
<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>
Hier ist der gesamte HTML-Code für den Körper die Website von page_source:
(https://pastebin.com/zpd4iF05)
Und für den Python-Code, den ich um das Element zu finden versucht, zu verwenden:
(https://pastebin.com/aW40P86u)
AHHH ja, es funktioniert !!!!!!! Ich musste nur den Kartentyp in eine Liste konvertieren mit lis = list (Werte) Dank a Ton! Kann dir nicht genug danken! – programmingnovice