我有下面的代码。我试图了解
re.compile('ctl(\d\d)_MainContent_ctl(\d\d)_DataDetails_ctl(\d\d)_trGBKItem')
确实是,为什么
tstsoup.find_all('tr', tstgradebook_row_id)
返回一个空列表。
我在下面提供了一个tstsoup示例,在其中我用“ ...”替换了一些块,以便将其发布。它来自
tstsoup = BeautifulSoup(driver.page_source)
此代码遵循仓库中的代码
https://github.com/AlbanyCompSci/aeries-api
在Gradebook.py文件中的。我正在用它来尝试编写脚本来登录并提高我的孩子的高中成绩。
代码:
import pandas as pd
import numpy as np
import os
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
Options
options = Options()
chrome_options = Options()
options.add_argument('headless') #downlod Chrome driver.exe
driver = webdriver.Chrome(executable_path=os.path.abspath("chromedriver"), chrome_options=chrome_options)
import re, dateutil.parser
from bs4 import BeautifulSoup
# tstsoup
tstgradebook_row_id = {'id': re.compile('ctl(\d\d)_MainContent_ctl(\d\d)_DataDetails_ctl(\d\d)_trGBKItem')}
# tstgradebook_row_id
tstgradebook_rows = tstsoup.find_all('tr', tstgradebook_row_id)
tstgradebook_rows
输出:
[]
样本数据:
tstsoup
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html class="k-webkit k-webkit70" xmlns="http://www.w3.org/1999/xhtml"><head><title>
Gradebook Summary
</title><meta content="initial-scale=1" id="ctl00_viewport" name="viewport"/><link href="favicon.ico" rel="shortcut icon" type="image/x-icon"/><link href="favicon.ico" rel="icon" type="image/x-icon"/><link href="/ParentPortal/Content/AjaxControlToolkit/Styles/Bundle?v=nap9lZtcl5K2gETjyyPCBXbWNbj8GlEheXK38ePUqDw1" rel="stylesheet"/>
<link href="StyleSheets/aeries.common.min.css?v=20160413" rel="stylesheet" type="text/css"/><link href="StyleSheets/aeries.default.min.css?v=20160413" rel="stylesheet" type="text/css"/><link href="StyleSheets/aeries-responsive.css" rel="stylesheet" type="text/css"/><link href="StyleSheets/Sofia.css" rel="stylesheet" type="text/css"/><link href="StyleSheets/GeneralLight.css" id="ctl00_BaseCSS" rel="stylesheet" type="text/css"/><link href="StyleSheets/calendar-stylesheet.css" rel="stylesheet" type="text/css"/><link href="KendoUI/kendo.common.min.css?v=2017.1.118" rel="stylesheet" type="text/css"/><link href="KendoUI/kendo.rtl.min.css?v=2017.1.118" rel="stylesheet" type="text/css"/><link href="KendoUI/kendo.bootstrap.min.css?v=2017.1.118" rel="stylesheet" type="text/css"/><link href="StyleSheets/bootstrap/bootstrap.css?v=2017.1.118" rel="stylesheet" type="text/css"/><link href="StyleSheets/bootstrap/bootstrap-tour.min.css?v=20170522" rel="stylesheet" type="text/css"/><link href="KendoUI/kendo.dataviz.min.css?v=2017.1.118" rel="stylesheet" type="text/css"/><link href="KendoUI/kendo.dataviz.default.min.css?v=2017.1.118" rel="stylesheet" type="text/css"/><link href="StyleSheets/font-awesome/font-awesome.min.css" rel="stylesheet" type="text/css"/><link href="StyleSheets/aeries-kendo-win.min.css" rel="stylesheet" type="text/css"/><link href="StyleSheets/CheckBoxes.min.css?vsn=20150929" rel="stylesheet" type="text/css"/><link href="StyleSheets/aeries-master.min.css?vsn=20160301" rel="stylesheet" type="text/css"/>
<script src="ClientScripts/ControlPositions.js?vsn=20170822" type="text/javascript"></script>
<script src="ClientScripts/ExpandOut.js" type="text/javascript"></script>
<script src="ClientScripts/XMLCommunications.js" type="text/javascript"></script>
<script src="ClientScripts/xmldom.js" type="text/javascript"></script>
<script src="Scripts/require/TimeOut.js?vsn=20180509" type="text/javascript"></script>
<script src="ClientScripts/calendar.js?vsn20141202" type="text/javascript"></script>
<script src="ClientScripts/EmailStuff.js?vsn=20160428" type="text/javascript"></script>
<script src="ClientScripts/jquery.min.js?v=1.12.3" type="text/javascript"></script>
<script src="ClientScripts/jquery.validate.min.js" type="text/javascript"></script>
<script src="ClientScripts/jquery.validate.unobtrusive.min.js" type="text/javascript"></script>
<script src="ClientScripts/jquery.unobtrusive-ajax.min.js" type="text/javascript"></script>
<script src="KendoUI/kendo.all.min.js?v=2017.1.118" type="text/javascript"></script>
<script src="KendoUI/kendo.aspnetmvc.min.js?v=2017.1.118" type="text/javascript"></script>
<script src="Scripts/velocity.min.js" type="text/javascript"></script>
<script src="ClientScripts/General.js?vsn=20180824" type="text/javascript"></script>
<script src="ClientScripts/StudentBackpack.js?vsn=20161208" type="text/javascript"></script>
<script type="text/javascript">window.defaultStatus="Welcome to Aeries";</script>
<script src="ClientScripts/aeries-kendo-windows-1.0.4.js?vsn=20160401" type="text/javascript"></script>
<script src="ClientScripts/UserOptions.js?vsn=20160504" type="text/javascript"></script>
<script src="ClientScripts/aeries-pagination.js?vsn=20160309" type="text/javascript"></script>
<script src="Scripts/bootstrap.min.js" type="text/javascript"></script>
<script src="ClientScripts/jquery.slimscroll.min.js" type="text/javascript"></script>
<script src="Scripts/bootstrap-tour.min.js?v=20170522" type="text/javascript"></script>
<script src="ClientScripts/Tours.js?v=20180227" type="text/javascript"></script>
<script src="Tracking.vbhtml?636756623367579132" type="text/javascript"></script>
<script src="ClientScripts/demo-feedback_js.js" type="text/javascript"></script>
<link href="ClientScripts/demo-feedback_css.css" rel="stylesheet" type="text/css"/>
<!-- PM - disable tracking for now.
<link rel='stylesheet' type='text/css' href='//aeriestools.tech/screenshot-feedback/feedback.css?636756623367579132' />
<script type='text/javascript' src='//aeriestools.tech/tracking.js?636756623367579132'></script>
-->
<script type="text/javascript">
$(document).ready(function () {
if (kendo.support.mobileOS) {
//GeneralFunctions.IsDemoServer(CheckForMobileVersion_IsDemoServer_Complete);
}
...
</script>
<script src="GeneralFunctions.asmx/js" type="text/javascript"></script>
<script src="SecurityFunctions.asmx/js" type="text/javascript"></script>
<div class="aspNetHidden">
<input id="__VIEWSTATEGENERATOR" name="__VIEWSTATEGENERATOR" type="hidden" value="868F4997"/>
</div>
<script type="text/javascript">
//<![CDATA[
Sys.WebForms.PageRequestManager._initialize('ctl00$TheMasterScriptManager', 'aspnetForm', ['tctl00$MainContent$subStuTopAll$subQuickCON$subQuickCON_UpdatePanel','','tctl00$MainContent$subGBS$upPrint',''], [], [], 90, 'ctl00');
//]]>
</script>
<div class="view" data-root-url="https://abip.fsusd.org/ParentPortal/" data-school-code="520" style="height: 100%">
<table class="full NoPadding a-expand">
<tbody><tr id="ctl00_trTop">
<td class="ac" valign="top">
<nav class="navbar navbar-l" id="navparent">
<div class="container-fluid" id="nav-container">
<div class="navbar-header" style="float:left;">
<div class="pull-left">
<div class="sidebar-logo-a">
<a href="Default.aspx" title="Aeries Home">
<img alt="Aeries" onerror="this.src='images/aeries-logo-a.png'; this.onerror=null;" src="images/aeries-logo-a.png" title="Aeries Student Information System"/>
</a>
</div>
</div>
<ul class="nav navbar-nav navbar-left" id="nav-school-settings">
<li class="school-year-nav dropdown-submenu aeries-background-green-light" id="ctl00_schoolYearNav">
<span class="school-year-nolink-nav-text NoWrap" id="ctl00_lblSchoolYear">2018-2019</span>
</li>
<li class="dropdown-submenu" id="school-dropdown-wrapper">
<span class="school-name-nolink-nav-text NoWrap" id="ctl00_lblSchoolName" title="School 520">Rodriguez High</span>
</li>
<li>
<input class="MasterSC" id="ctl00_SC" name="ctl00$SC" type="hidden" value="520"/>
<input class="MasterSN" id="ctl00_SN" name="ctl00$SN" type="hidden" value="5272"/>
<input class="MasterPID" id="ctl00_PID" name="ctl00$PID" type="hidden" value="154138"/>
</li>
</ul>
</div>
<ul class="nav navbar-nav navbar-right" id="nav-settings">
<li class="dropdown-submenu nav-buttons">
<a class="dropdown-toggle expandable" data-toggle="dropdown" href="#" id="nav-account-dropdown-icon" title="Settings">
<span class="normalmode">
<span id="ctl00_lblWelcomeName">jennscorner@gmail.com</span>
<span class="icon-collapsed"></span>
</span>
<span class="tinymode">
<span class="k-icon k-i-custom" id="collapsed-settings-icon"></span>
</span>
</a>
<ul class="dropdown-menu SubTab forceRight" id="nav-account-dropdown" style="margin-top:0; padding-top:0;">
<li class="zebra" id="mobileTestdrive" style="display: none;"></li>
<li class="zebra" css="ContextMenuItem" id="ctl00_liParentNotification">
<a href="/ParentPortal/ParentNotificationPreferences.aspx" id="aParentNotification">Parent Notification Preferences</a>
</li>
<li class="zebra">
<a css="ContextMenuItem" href="/ParentPortal/ChangePassword.aspx" id="aChangePWD">Change Password</a>
</li>
<li class="zebra">
<a css="ContextMenuItem" href="/ParentPortal/ChangeEmail.aspx" id="aChangeEM">Change Email</a>
</li>
<li class="zebra">
<a css="ContextMenuItem" href="/ParentPortal/AddNewStudentToParent.aspx" id="aAddSTU">Add New Student To Your Account</a>
</li>
<li class="zebra">
<a css="ContextMenuItem" href="/ParentPortal/LogOut.aspx" id="aLogOut">Log Out</a>
</li>
</ul>
</li>
</ul>
</div>
</nav>
<div id="ctl00_ParNav_ParNav"><table border="0" cellpadding="0" cellspacing="0" width="100%"><tbody><tr><td align="left" class="raised "><table border="0" cellpadding="0" cellspacing="0" class="menutable"><tbody><tr valign="top"><td><div class="Top_Parent" id="Top_1"><a aria-haspopup="true" class="topdynamicmenu" href="Default.aspx" id="Home" name="Home" onclick="return true" target="">Home</a></div></td><td><div class="Top_Parent" id="Top_2"><a aria-haspopup="true" class="topdynamicmenu" href="javascript:void(0);" id="Student Info" name="Student Info" onclick="return true" target="">Student Info</a><div class="SubTab" id="Sub_2"><a class="zebra" href="StudentProfile.aspx" id="Profile" name="Profile">Profile</a><a class="zebra" href="Students.aspx" id="Demographics" name="Demographics">Demographics</a><a class="zebra" href="EmergencyContacts.aspx" id="Contacts" name="Contacts">Contacts</a><a class="zebra" href="ClassesOld.aspx" id="Classes" name="Classes">Classes</a><a class="zebra" href="Fees.aspx" id="Fees and Fines" name="Fees and Fines">Fees and Fines</a><a class="zebra" href="WorkPermit.aspx" id="Work Permit" name="Work Permit">Work Permit</a></div></div></td><td><div class="Top_Parent" id="Top_3"><a aria-haspopup="true" class="topdynamicmenu" href="javascript:void(0);" id="Attendance" name="Attendance" onclick="return true" target="">Attendance</a><div class="SubTab" id="Sub_3"><a class="zebra" href="Attendance.aspx" id="Attendance" name="Attendance">Attendance</a></div></div></td><td><div class="Top_Parent" id="Top_4"><a aria-haspopup="true" class="visitedtopmenu" href="javascript:void(0);" id="Grades" name="Grades" onclick="return true" target="">Grades</a><div class="SubTab" id="Sub_4"><a class="visitedsubmenu" href="GradebookSummary.aspx" id="Gradebook" name="Gradebook">Gradebook</a><a class="zebra" href="GradebookDetails.aspx" id="Gradebook Details" name="Gradebook Details">Gradebook Details</a><a class="zebra" href="StudentReportCardHistory.aspx" id="Report Card History" name="Report Card History">Report Card History</a><a class="zebra" href="Grades.aspx" id="Grades" name="Grades">Grades</a><a class="zebra" href="GraduationRequirements.aspx" id="Graduation Status" name="Graduation Status">Graduation Status</a><a class="zebra" href="Transcripts.aspx" id="Transcripts <span class='metadata' style='display: none;'>History</span>" name="Transcripts <span class='metadata' style='display: none;'>History</span>">Transcripts <span class="metadata" style="display: none;">History</span></a><a class="zebra" href="CollegeEntrance.aspx" id="College Entrance Requirements" name="College Entrance Requirements">College Entrance Requirements</a><a class="zebra" href="StudentStandardsBasedProgress.aspx" id="Standards Based Progress Dashboard" name="Standards Based Progress Dashboard">Standards Based Progress Dashboard</a></div></div></td><td><div class="Top_Parent" id="Top_5"><a aria-haspopup="true" class="topdynamicmenu" href="javascript:void(0);" id="Medical" name="Medical" onclick="return true" target="">Medical</a><div class="SubTab" id="Sub_5"><a class="zebra" href="MedicalHistory.aspx" id="Medical History" name="Medical History">Medical History</a><a class="zebra" href="Immunizations.aspx" id="Immunizations" name="Immunizations">Immunizations</a></div></div></td><td><div class="Top_Parent" id="Top_6"><a aria-haspopup="true" class="topdynamicmenu" href="javascript:void(0);" id="Test Scores" name="Test Scores" onclick="return true" target="">Test Scores</a><div class="SubTab" id="Sub_6"><a class="zebra" href="TestDetails.aspx" id="Test Details" name="Test Details">Test Details</a><a class="zebra" href="TestScores.aspx" id="Test Scores" name="Test Scores">Test Scores</a><a class="zebra" href="CollegeTestScores.aspx" id="College Entrance Tests" name="College Entrance Tests">College Entrance Tests</a><a class="zebra" href="PhysicalFitnessTestResults.aspx" id="Physical Fitness Test Results" name="Physical Fitness Test Results">Physical Fitness Test Results</a></div></div></td><td><div class="Top_Parent" id="Top_7"><a aria-haspopup="true" class="topdynamicmenu" href="javascript:void(0);" id="Change Student" name="Change Student" onclick="return true" target="">Change Student</a><div class="SubTab" id="Sub_7"><a class="zebra" href="ChangeStudent.aspx?cache=10%2f20%2f2018+12%3a58%3a56+PM&SC=520&SN=6703&ReturnPage=GradebookSummary.aspx&name=520_6703&id=520_6703" id="Anderson, Brett E - Grd 9 - Rodriguez High" name="Anderson, Brett E - Grd 9 - Rodriguez High" target="_blank">Anderson, Brett E - Grd 9 - Rodriguez High</a><a class="zebra" href="ChangeStudent.aspx?cache=10%2f20%2f2018+12%3a58%3a56+PM&SC=520&SN=5272&ReturnPage=GradebookSummary.aspx&name=520_5272&id=520_5272" id="Anderson, Drew J - Grd 11 - Rodriguez High" name="Anderson, Drew J - Grd 11 - Rodriguez High" target="_blank">Anderson, Drew J - Grd 11 - Rodriguez High</a><a class="zebra" href="AddNewStudentToParent.aspx" id="Add New Student To Your Account" name="Add New Student To Your Account">Add New Student To Your Account</a></div></div></td></tr></tbody></table></td></tr></tbody></table></div>
</td>
</tr>
<tr style="background-color:#F5F5F5; height: 525px; min-height:525px;"><td class="al" style="padding: 5px 5px 5px 5px; min-height:525px;" valign="top">
<div style="width:100%;"><span class="RedText" id="ctl00_lblAlert"></span></div>
<div class="page-head">
<div class="page-title">
<span class="lblPageTitle" id="ctl00_MainContent_subPageHead_lblPageTitle">Gradebook Summary</span>
</div>
<div class="page-options">
<span class="fa fa-print fa-2x page-option-default" id="print-submit" title="Print"></span>
<div class="hide">
<span id="favorite-submit" title="Favorite This Page"><span class="favorite-icon fa fa-star-o fa-2x page-option-default" id="ctl00_MainContent_subPageHead_FavoriteIcon"></span></span>
</div>
</div>
</div>
<input id="ctl00_MainContent_subPageHead_RedFlagValue" name="ctl00$MainContent$subPageHead$RedFlagValue" type="hidden"/>
<div id="StartTourWelcome" style="display: none;">
<div style="padding: 5px 0 20px 0;">
Would you like to take a tour of this page and its features?
</div>
<a class="k-button" href="#" id="StartTourWelcomeNo">No</a>
<div style="float:right">
<a class="k-button-primary" href="#" id="StartTourWelcomeYes">Yes</a>
</div>
</div>
<script>
...
<td class="Data NoWrap ac">Y</td>
<td class="Data NoWrap ac"></td>
</tr>
<tr class="zebratr">
<td class="Data ac aeries-dark-red"><b> </b></td>
<td class="Data NoWrap">
<a href="EmergencyContacts.aspx?SQ=3#SQ3CDS48705400000000" title="Go to Contact">Sean Anderson</a>
</td>
<td class="Data NoWrap">(707) 640-9807</td>
<td class="Data NoWrap"></td>
<td class="Data NoWrap"></td>
<td class="Data NoWrap">
Family Member
</td>
<td class="Data NoWrap ac"></td>
<td class="Data NoWrap ac"></td>
</tr>
<tr class="zebratr">
<td class="Data ac aeries-dark-red"><b> </b></td>
<td class="Data NoWrap">
<a href="EmergencyContacts.aspx?SQ=4#SQ4CDS48705400000000" title="Go to Contact">Travis Shields</a>
</td>
<td class="Data NoWrap"></td>
<td class="Data NoWrap"></td>
<td class="Data NoWrap">(415) 490-8826</td>
<td class="Data NoWrap">
Aunt/Uncle
</td>
<td class="Data NoWrap ac"></td>
<td class="Data NoWrap ac"></td>
</tr>
<tr class="zebratr">
<td class="Data ac aeries-dark-red"><b> </b></td>
<td class="Data NoWrap">
<a href="EmergencyContacts.aspx?SQ=8#SQ8CDS48705400000000" title="Go to Contact">Dr. Finklestein</a>
</td>
<td class="Data NoWrap">(707) 641-1900</td>
<td class="Data NoWrap"></td>
<td class="Data NoWrap"></td>
<td class="Data NoWrap">
Doctor/Health Plan
</td>
<td class="Data NoWrap ac"></td>
<td class="Data NoWrap ac"></td>
</tr>
</tbody></table>
</td>
</tr>
</tbody></table>
<script type="text/javascript">
$(document).ready(function () {
$("div[id$='_pnlQuickCON'] .widget-title").html($("div[id$='_pnlQuickCON'] .widget-title").html() + " For " + $(".lblName").text());
});
</script>
</div>
</div>
</div>
</div></div><div class="modalBackground" data-act-control-type="modalPopupBackground" id="QuickCONBehavior_backgroundElement" style="display: none; position: fixed; left: 0px; top: 0px; z-index: 10000;"></div></td></tr>
<tr><td>
<table border="0" cellpadding="0" cellspacing="0" width="100%"><tbody><tr>
<td class="al" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; color: #000000;">Aeries Version <span id="ctl00_lblVersion">8.18.9.28</span></td>
<td class="ar" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; color: #000000;"><span id="ctl00_lblCopyright">Copyright © 1995-2018 Aeries Software. All Rights Reserved.</span></td>
</tr></tbody></table>
</td></tr>
</tbody></table>
</div>
<a class="hide" href="javascript:__doPostBack('ctl00$btnPrevious','')" id="ctl00_btnPrevious"></a>
<a class="hide" href="javascript:__doPostBack('ctl00$btnNext','')" id="ctl00_btnNext"></a>
<script language="javascript"> var timeoutIsParent = true; var global_SessionTimer; var global_WarningTimer; var global_SessionTimeout = 1200000; var global_WarningTimeout = 900000; initSessionTimer(1200000,900000);</script>
<script type="text/javascript">
//<![CDATA[
function PrintReport(){__doPostBack('ctl00$MainContent$subGBS$btnPrint','');}Sys.Application.add_init(function() {
$create(Sys.Extended.UI.ModalPopupBehavior, {"backgroundCssClass":"modalBackground","dropShadow":true,"dynamicServicePath":"/ParentPortal/GradebookSummary.aspx","id":"QuickCONBehavior","popupControlID":"ctl00_MainContent_subStuTopAll_pnlQuickCON"}, null, null, $get("ctl00_MainContent_subStuTopAll_btnShowQuickCON"));
});
Sys.Application.add_init(function() {
$create(Sys.Extended.UI.ModalPopupBehavior, {"backgroundCssClass":"modalBackground","cancelControlID":"ctl00_MainContent_subGBS_imgCloseTrendGraph","dynamicServicePath":"/ParentPortal/GradebookSummary.aspx","id":"ShowTrendGraph","popupControlID":"ctl00_MainContent_subGBS_pnlTrendGraph"}, null, null, $get("ctl00_MainContent_subGBS_btnShowTrendPopup"));
});
//]]>
</script>
</form>
<script type="text/javascript">
// remove the mobile portal link on desktop browsers
if (!kendo.support.mobileOS) {
$('#mobileTestdrive').hide();
if ($get("mobileTestdrive")) { $get("mobileTestdrive").innerHTML = ""; }
} else {
$('#mobileTestdrive').show();
}
window.masterSC = $('.MasterSC').val();
window.masterSN = $('.MasterSN').val();
window.masterID = $('.MasterPID').val();
</script>
<script type="text/javascript">
$(document).ready(function() {
window.masterSC = $('.MasterSC').val();
window.masterSN = $('.MasterSN').val();
window.masterID = $('.MasterPID').val();
});
</script>
<div class="k-widget k-window" data-role="draggable" style="padding-top: 35px; min-width: 90px; min-height: 50px; width: 400px; height: 235px; display: none;"><div class="k-window-titlebar k-header" style="margin-top: -35px;"> <span class="k-window-title" id="kendoCommonPopup_wnd_title"></span><div class="k-window-actions"><a aria-label="Close" class="k-button k-bare k-button-icon k-window-action" href="#" role="button"><span class="k-icon k-i-close"></span></a></div></div><div aria-labelledby="kendoCommonPopup_wnd_title" class="k-window-content k-content" data-role="window" id="kendoCommonPopup" role="dialog" tabindex="0"></div><div class="k-resize-handle k-resize-n"></div><div class="k-resize-handle k-resize-e"></div><div class="k-resize-handle k-resize-s"></div><div class="k-resize-handle k-resize-w"></div><div class="k-resize-handle k-resize-se"></div><div class="k-resize-handle k-resize-sw"></div><div class="k-resize-handle k-resize-ne"></div><div class="k-resize-handle k-resize-nw"></div></div></body></html>
答案 0 :(得分:0)
我发现我要查找的ID的模式已更改。现在看起来像'ctl(\ d \ d)_MainContent_subGBS_DataDetails_ctl(\ d \ d)_trGBKItem',如果使用该模式,我将获得正确的源代码块。