Quicker way to search HTML files using extractHTMLText or something else to improve time on code

4 ビュー (過去 30 日間)
Eric Lopez
Eric Lopez 2022 年 1 月 16 日
回答済み: Shivam 2024 年 1 月 12 日
Hello I have a personal project I am working on that searches my school's schedules to check to see when a classroom is busy with a class or free to use. I used extractHTMLText to extract the info from the school's website but I need to do that from about 123 urls which slows down my code. It takes about 20 mins to run and search for one classroom. I am wondering if there is a quicker way for my to do this with or without using extractHTMLText. Below is my code and I tried to point out where extractHTMLText is in the code, that is where my code slows down and takes the longest.
clear;
close;
clc;
ACCT='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/ACCT.html';
AFRS='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/AFRS.html';
ASLD='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/ASLD.html';
AIS='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/AIS.html';
AMST='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/AMST.html';
ANTH='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/ANTH.html';
ARAB='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/ARAB.html';
ART='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/ART.html';
AH='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/AH.html';
AAAS='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/AAAS.html';
ASAM='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/ASAM.html';
A_ST='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/AxST.html';
ASTR='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/ASTR.html';
AT='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/AT.html';
ATEP='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/ATEP.html';
ATHL='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/ATHL.html';
BIOL='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/BIOL.html';
BME='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/BME.html';
BLAW='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/BLAW.html';
CBA='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/CBA.html';
KHMR='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/KHMR.html';
CHE='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/CHzE.html';
CHEM='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/CHEM.html';
CHLS='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/CHLS.html';
CDFS='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/CDFS.html';
CHIN='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/CHIN.html';
CE='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/CzE.html';
CLSC='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/CLSC.html';
COMM='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/COMM.html';
CWL='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/CWL.html';
CECS='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/CECS.html';
CEM='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/CEM.html';
CAFF='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/CAFF.html';
COUN='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/COUN.html';
CRJU='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/CRJU.html';
DANC='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/DANC.html';
DESN='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/DESN.html';
DPT='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/DPT.html';
ECON='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/ECON.html';
EDLD='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/EDLD.html';
EDCI='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/EDCI.html';
EDEC='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/EDEC.html';
EDEL='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/EDEL.html';
EDSE='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/EDSE.html';
EDSS='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/EDSS.html';
EDSP='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/EDSP.html';
EDAD='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/EDAD.html';
EDP='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/EDzP.html';
ETEC='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/ETEC.html';
EE='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/EzE.html';
EMER='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/EMER.html';
ENGR='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/ENGR.html';
ET='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/EzT.html';
ENGL='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/ENGL.html';
ESP='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/ESzP.html';
FMD='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/FMD.html';
FIL='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/FIL.html';
FEA='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/FEA.html';
FIN='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/FIN.html';
FSCI='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/FSCI.html';
FREN='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/FREN.html';
GEOG='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/GEOG.html';
GEOL='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/GEOL.html';
GERM='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/GERM.html';
GERN='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/GERN.html';
GBA='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/GBA.html';
GK='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/GK.html';
HCA='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/HCA.html';
HSC='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/HzSC.html';
HEBW='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/HEBW.html';
HIST='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/HIST.html';
HM='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/HM.html';
HDEV='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/HDEV.html';
HRM='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/HRM.html';
IS='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/IzS.html';
I_ST='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/IxST.html';
ITAL='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/ITAL.html';
JAPN='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/JAPN.html';
JOUR='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/JOUR.html';
KIN='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/KIN.html';
KOR='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/KOR.html';
LAT='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/LAT.html';
C_LA='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/CxLA.html';
L_ST='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/LxST.html';
LING='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/LING.html';
MGMT='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/MGMT.html';
MKTG='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/MKTG.html';
MATH='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/MATH.html';
MTED='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/MTED.html';
MAE='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/MAE.html';
MS='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/MzS.html';
MUS='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/MUS.html';
NSCI='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/NSCI.html';
NRSG='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/NRSG.html';
NUTR='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/NUTR.html';
PHIL='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/PHIL.html';
PHSC='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/PHSC.html';
PHYS='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/PHYS.html';
POSC='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/POSC.html';
PSY='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/PSY.html';
PPA='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/PPA.html';
REC='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/REC.html';
R_ST='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/RxST.html';
RGR='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/RGR.html';
RUSS='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/RUSS.html';
SCED='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/SCED.html';
SCAE='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/SCAE.html';
SW='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/SzW.html';
SOC='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/SOC.html';
SPAN='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/SPAN.html';
SLP='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/SLP.html';
STAT='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/STAT.html';
SDHE='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/SDHE.html';
SRL='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/SRL.html';
S_I='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/SxI.html';
SCM='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/SCM.html';
THEA='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/THEA.html';
TRST='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/TRST.html';
UNIV='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/UNIV.html';
UHP='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/UHP.html';
UDCP='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/UDCP.html';
VIET='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/VIET.html';
WGSS='http://web.csulb.edu/depts/enrollment/registration/class_schedule/Spring_2022/By_Subject/WGSS.html';
%ACCT; AFRS; ASLD; AIS; AMST; ANTH; ARAB; ART; AH; AAAS; ASAM; A_ST; ASTR; AT; ATEP; ATHL;
% BIOL; BME; BLAW; CBA; KHMR; CHE; CHEM; CHLS; CDFS; CHIN; CE; CLSC; COMM; CWL; CECS; CEM;
% CAFF; COUN; CRJU; DANC; DESN; DPT; ECON; EDLD; EDCI; EDEC; EDEL; EDSE; EDSS; EDSP; EDAD; EDP;
% ETEC; EE; EMER; ENGR; ET; ENGL; ESP; FMD; FIL; FEA; FIN; FSCI; FREN; GEOG; GEOL; GERM;
% GERN; GBA; GK; HCA; HSC; HEBW; HIST; HM; HDEV; HRM; IS; I_ST; ITAL; JAPN; JOUR; KIN;
% KOR; LAT; C_LA; L_ST; LING; MGMT; MKTG; MATH; MTED; MAE; MS; MUS; NSCI; NRSG; NUTR; PHIL;
% PHSC; PHYS; POSC; PSY; PPA; REC; R_ST; RGR; RUSS; SCED; SCAE; SW; SOC; SPAN; SLP; STAT;
% SDHE; SRL; S_I; SCM; THEA; TRST; UNIV; UHP; UDCP; VIET; WGSS
CSULB_Class_Schedules={ACCT; AFRS; ASLD; AIS; AMST; ANTH; ARAB; ART; AH; AAAS; ASAM; A_ST; ASTR; AT; ATEP; ATHL;
BIOL; BME; BLAW; CBA; KHMR; CHE; CHEM; CHLS; CDFS; CHIN; CE; CLSC; COMM; CWL; CECS; CEM;
CAFF; COUN; CRJU; DANC; DESN; DPT; ECON; EDLD; EDCI; EDEC; EDEL; EDSE; EDSS; EDSP; EDAD; EDP;
ETEC; EE; EMER; ENGR; ET; ENGL; ESP; FMD; FIL; FEA; FIN; FSCI; FREN; GEOG; GEOL; GERM;
GERN; GBA; GK; HCA; HSC; HEBW; HIST; HM; HDEV; HRM; IS; I_ST; ITAL; JAPN; JOUR; KIN;
KOR; LAT; C_LA; L_ST; LING; MGMT; MKTG; MATH; MTED; MAE; MS; MUS; NSCI; NRSG; NUTR; PHIL;
PHSC; PHYS; POSC; PSY; PPA; REC; R_ST; RGR; RUSS; SCED; SCAE; SW; SOC; SPAN; SLP; STAT;
SDHE; SRL; S_I; SCM; THEA; TRST; UNIV; UHP; UDCP; VIET; WGSS};
CSULB_Class_Schedules=string(CSULB_Class_Schedules);
Initilizer_1=1;
Initilizer_2=1;
while Initilizer_1 == 1
prompt = 'Would you like to check classroom availablilty? Y/N \n';
User_Input=input(prompt,'s');
Initilizer_1=1;
Initilizer_2=1;
if isequal(User_Input,'Y') || isequal(User_Input,'y')
Classroom_Location_Input='Enter Class Location (Ex. COB-123):';
Desired_Classroom_Location=input(Classroom_Location_Input,'s');
selector="td";
Check_Length_CSULB_Class_Schedules=1;
MWF_AM_Counter=0;
MWF_PM_Counter=0;
TuTh_AM_Counter=0;
TuTh_PM_Counter=0;
FSa_AM_Counter=0;
FSa_PM_Counter=0;
clc;
clear MWF_AM_Classroom_Combo MWF_PM_Classroom_Combo TuTh_AM_Classroom_Combo TuTh_PM_Classroom_Combo FSa_AM_Classroom_Combo FSa_PM_Classroom_Combo;
MWF_AM_Classroom_Combo(1,3)=string();
MWF_PM_Classroom_Combo(1,3)=string();
TuTh_AM_Classroom_Combo(1,3)=string();
TuTh_PM_Classroom_Combo(1,3)=string();
FSa_AM_Classroom_Combo(1,3)=string();
FSa_PM_Classroom_Combo(1,3)=string();
tic
while Initilizer_2==1
Length_CSULB_Class_Schedules=height(CSULB_Class_Schedules);
url=CSULB_Class_Schedules(Check_Length_CSULB_Class_Schedules,:);
code=webread(url);
tree=htmlTree(code);
subtrees=findElement(tree,selector);
subtrees(1:length(subtrees));
------> Extracted_HTML_Text=extractHTMLText(subtrees);
Counter_2=0;
Counter_3=0;
Extracted_Desried_Classroom=string();
Days_of_the_Week_Classroom=string();
Times_Classroom=string();
Classroom=string();
Length_Extracted_HTML_Text=height(Extracted_HTML_Text);
for Counter_1=1:Length_Extracted_HTML_Text
Confirmed_Classroom_Location=contains(Extracted_HTML_Text,Desired_Classroom_Location);
if Confirmed_Classroom_Location(Counter_1) == 1
Counter_2=Counter_2+1;
Extracted_Desried_Classroom(Counter_2)=Extracted_HTML_Text(Counter_1);
Classroom_Matches=contains(Extracted_Desried_Classroom,Desired_Classroom_Location);
if Classroom_Matches(Counter_2)==1
Counter_3=Counter_3+1;
Days_of_the_Week_Classroom(Counter_3)=Extracted_HTML_Text(Counter_1-3);
Times_Classroom(Counter_3)=Extracted_HTML_Text(Counter_1-2);
Classroom(Counter_3)=Extracted_Desried_Classroom(Counter_2);
end
end
end
if Length_CSULB_Class_Schedules==Check_Length_CSULB_Class_Schedules
Initilizer_2=0;
end
Check_Length_CSULB_Class_Schedules=Check_Length_CSULB_Class_Schedules+1;
if Initilizer_1==1
y=str2double(Classroom);
if Counter_3 ~= 0
Column_Days_of_the_Week_Classroom=Days_of_the_Week_Classroom';
Column_Times_Classroom=Times_Classroom';
Column_Classroom=Classroom';
datetime.setDefaultFormats('default','hh:mm a');
[Xsorted,I] = sort(Column_Times_Classroom);
Ysorted = Column_Days_of_the_Week_Classroom(I);
Zsorted=Column_Classroom(I);
XYZ=[Ysorted Xsorted Zsorted];
for Length_Column_Days_of_the_Week_Classroom=1:height(Column_Days_of_the_Week_Classroom)
fprintf('%s %6s %6s\r',Column_Days_of_the_Week_Classroom(Length_Column_Days_of_the_Week_Classroom), Column_Times_Classroom(Length_Column_Days_of_the_Week_Classroom), Column_Classroom(Length_Column_Days_of_the_Week_Classroom))
%clc;
% fprintf('Please wait... %s %6s %6s\r')
% fprintf('\n')
% pause(1)
end
fprintf('\n')
for Length_Column_Days_of_the_Week_Classroom=1:height(Column_Days_of_the_Week_Classroom)
if contains(XYZ(Length_Column_Days_of_the_Week_Classroom),'M')||contains(XYZ(Length_Column_Days_of_the_Week_Classroom),'MW')||contains(XYZ(Length_Column_Days_of_the_Week_Classroom),'W')||contains(XYZ(Length_Column_Days_of_the_Week_Classroom),'MWF')
if contains(XYZ(Length_Column_Days_of_the_Week_Classroom,2),'AM')
MWF_AM_Counter=MWF_AM_Counter+1;
MWF_AM_Classroom_Combo(MWF_AM_Counter,:)=XYZ(Length_Column_Days_of_the_Week_Classroom,:);
elseif contains(XYZ(Length_Column_Days_of_the_Week_Classroom,2),'PM')
MWF_PM_Counter=MWF_PM_Counter+1;
MWF_PM_Classroom_Combo(MWF_PM_Counter,:)=XYZ(Length_Column_Days_of_the_Week_Classroom,:);
end
elseif contains(XYZ(Length_Column_Days_of_the_Week_Classroom),'Tu')||contains(XYZ(Length_Column_Days_of_the_Week_Classroom),'TuTh')||contains(XYZ(Length_Column_Days_of_the_Week_Classroom),'Th')
if contains(XYZ(Length_Column_Days_of_the_Week_Classroom,2),'AM')
TuTh_AM_Counter=TuTh_AM_Counter+1;
TuTh_AM_Classroom_Combo(TuTh_AM_Counter,:)=XYZ(Length_Column_Days_of_the_Week_Classroom,:);
elseif contains(XYZ(Length_Column_Days_of_the_Week_Classroom,2),'PM')
TuTh_PM_Counter=TuTh_PM_Counter+1;
TuTh_PM_Classroom_Combo(TuTh_PM_Counter,:)=XYZ(Length_Column_Days_of_the_Week_Classroom,:);
end
elseif contains(XYZ(Length_Column_Days_of_the_Week_Classroom),'F')||contains(XYZ(Length_Column_Days_of_the_Week_Classroom),'Sa')
if contains(XYZ(Length_Column_Days_of_the_Week_Classroom,2),'AM')
FSa_AM_Counter=FSa_AM_Counter+1;
FSa_AM_Classroom_Combo(FSa_AM_Counter,:)=XYZ(Length_Column_Days_of_the_Week_Classroom,:);
elseif contains(XYZ(Length_Column_Days_of_the_Week_Classroom,2),'PM')
FSa_PM_Counter=FSa_PM_Counter+1;
FSa_PM_Classroom_Combo(FSa_PM_Counter,:)=XYZ(Length_Column_Days_of_the_Week_Classroom,:);
end
end
end
end
end
end
IsMissing_MWF_AM_Classroom_Combo=ismissing(MWF_AM_Classroom_Combo);
if IsMissing_MWF_AM_Classroom_Combo(1,1)==0
for Length_Classroom_Combo=1:height(IsMissing_MWF_AM_Classroom_Combo)
end
end
fprintf('\n')
IsMissing_MWF_PM_Classroom_Combo=ismissing(MWF_PM_Classroom_Combo);
if IsMissing_MWF_PM_Classroom_Combo(1,1)==0
for Length_Classroom_Combo=1:height(IsMissing_MWF_PM_Classroom_Combo)
end
end
fprintf('\n')
IsMissing_TuTh_AM_Classroom_Combo=ismissing(TuTh_AM_Classroom_Combo);
if IsMissing_TuTh_AM_Classroom_Combo(1,1)==0
for Length_Classroom_Combo=1:height(IsMissing_TuTh_AM_Classroom_Combo)
end
end
fprintf('\n')
IsMissing_TuTh_PM_Classroom_Combo=ismissing(TuTh_PM_Classroom_Combo);
if IsMissing_TuTh_PM_Classroom_Combo(1,1)==0
for Length_Classroom_Combo=1:height(IsMissing_TuTh_PM_Classroom_Combo)
end
end
fprintf('\n')
IsMissing_FSa_AM_Classroom_Combo=ismissing(FSa_AM_Classroom_Combo);
if IsMissing_FSa_AM_Classroom_Combo(1,1)==0
for Length_Classroom_Combo=1:height(IsMissing_FSa_AM_Classroom_Combo)
end
end
fprintf('\n')
IsMissing_FSa_PM_Classroom_Combo=ismissing(FSa_PM_Classroom_Combo);
if IsMissing_FSa_PM_Classroom_Combo(1,1)==0
for Length_Classroom_Combo=1:height(IsMissing_FSa_PM_Classroom_Combo)
end
end
Classroom_Combo_Table=[MWF_AM_Classroom_Combo;MWF_PM_Classroom_Combo;TuTh_AM_Classroom_Combo;TuTh_PM_Classroom_Combo;FSa_AM_Classroom_Combo;FSa_PM_Classroom_Combo];
Classroom_Info_Table=uifigure;
uit=uitable(Classroom_Info_Table,'ColumnWidth','auto','Data',Classroom_Combo_Table);
end
toc
if isequal(User_Input,'N') || isequal(User_Input,'n')
Initilizer_1 = 0;
clc;
end
fprintf('Done \n')
end

回答 (1 件)

Shivam
Shivam 2024 年 1 月 12 日
Hi,
From the information provided, I understand that you are experiencing performance issues while monitoring your school's classroom schedules and determining their availability. You are utilizing the "extractHTMLText" function to extract schedule information from the school's website. However, the processing of 123 URLs significantly slows down your code, with each classroom location prompt search taking around 20 minutes.
You can follow the below workarounds to improve the performance of the code:
  • Extracted HTML text preprocessing: You can save the extracted HTML text corresponding to each URL in a cell array before the prompt appears for the class location input and reuse this previously fetched data for every prompt. It will reduce the need to run "extractHTMLText" for every URL with each prompt. You can follow the below workaround to modify the code:
% 1. Preprocess the extracted HTML text of 123 URLs and store it in a cell array
CSULB_Class_Schedules=string(CSULB_Class_Schedules);
htmlTreeArr_extractHTML = cell(height(CSULB_Class_Schedules), 1);
for i = 1:height(CSULB_Class_Schedules)
htmlTreeArr_extractHTML{i}= extractHTMLText(findElement(htmlTree(webread(CSULB_Class_Schedules(i, :))), "td"));
end
Initilizer_1=1;
Initilizer_2=1;
%.
%..
% 2. Use htmlTreeArr_extractHTML for each class location prompt.
while Initilizer_2==1
Length_CSULB_Class_Schedules=height(CSULB_Class_Schedules);
Extracted_HTML_Text = htmlTreeArr_extractHTML{Check_Length_CSULB_Class_Schedules};
Counter_2=0;
%.
%..
  • Parallel Processing: You can use MATLAB's parallel processing capabilities through functions like "parfor" or "parfeval" to handle multiple URLs at once. This will help in distributing the workload across multiple CPU cores.
You can refer to the following documentations to know more about "parfor" and "parfeval":
I hope it helps.
Thanks

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by