@@ -16,8 +16,10 @@ public class DispatchScheduler implements Scheduler {
1616 private static final String getProblemLinkPath = "//table[@class='table table-striped table-centered']/tbody/tr/td/a/text()" ; //得到题目名称Xpath路径
1717 private static final String submissionLinkPath = "//div[@class='row']/div/div/a/@href" ; //进入题目提交页面Xpath路径
1818 private static final String codePagePath = "//table[@id='result_testcases']/tbody/tr/td/a/@href" ; //进入题目代码页面Xpath路径
19- private static final String codePageStatusPath = "//table[@id='result_testcases]/t"
20- + "body/tr/td/a[@class='status-accepted text-success']/strong/text()" ; //题目提交状态Xpath路径
19+ // private static final String codePageStatusPath = "//table[@id='result_testcases]/t"
20+ // + "body/tr/td/a[@class='status-accepted text-success']/strong/text()"; //题目提交状态Xpath路径
21+ // private static final String codePageStatusPath = "//div[@class='row']/div/div/a/@href";
22+ private static final String codePageStatusPath = "//a[@class='text-danger status-accepted']/@href" ;
2123 private Logger myLog ;
2224 /**
2325 *
@@ -35,7 +37,7 @@ public void startProcess() {
3537 try {
3638 myLog .debug ("进入startProcess,试图初始化task queue" );
3739 List <String > list = downloader .problemListDownloader (problemLinkPath );
38- setTask (list );
40+ setTask (list , null );
3941 } catch (InterruptedException e ) {
4042 e .printStackTrace ();
4143 }
@@ -77,19 +79,16 @@ public void taskProcceed() {
7779 * @since 1.0.0
7880 */
7981 public void getDownloadResult (ParserTask task ) throws InterruptedException {
80- if (task .getType () == ParserTask .TaskType .GET_SUBMISION_URL ) {
81- myLog .debug ("正在获取问题提交列表url" );
82- List <String > list = downloader .problemDescriptionDownloader (task .getUrl (), submissionLinkPath );
83- setTask (list );
84- } else if (task .getType () == ParserTask .TaskType .GET_CODE_URL ) {
85- myLog .debug ("正在获取代码页面url" );
86- List <String > list = downloader .submissionListDownloader (task .getUrl (), codePagePath );
87- setTask (list );
88- } else if (task .getType () == ParserTask .TaskType .GET_CODE ) {
89- myLog .debug ("正在获取代码" );
90- //do something to get code
82+ if (task .getType ().equals (ParserTask .TaskType .SUBMISION_URL )) {
83+ myLog .debug ("该任务为获取问题代码" );
84+ List <String > list = downloader .problemDescriptionDownloader (task .getUrl (), codePageStatusPath );
85+ setTask (list , task .getType ());
86+ } else if (task .getType ().equals (ParserTask .TaskType .CODE_PAGE_URL )) {
87+ //获取代码
9188 } else {
92- System .out .println ("无法识别该url,请填写正确的url。" );
89+ myLog .debug ("正在获取问题提交列表,url为: " + task .getUrl ());
90+ List <String > list = downloader .problemDescriptionDownloader (task .getUrl (), submissionLinkPath );
91+ setTask (list , task .getType ());
9392 }
9493 }
9594
@@ -102,10 +101,18 @@ public void getDownloadResult(ParserTask task) throws InterruptedException {
102101 * @exception
103102 * @since 1.0.0
104103 */
105- public void setTask (List <String > list ) throws InterruptedException {
104+ public void setTask (List <String > list , ParserTask .TaskType type ) throws InterruptedException {
105+ if (list .size () == 0 ) return ;
106+ if (type != null && type .equals (ParserTask .TaskType .SUBMISION_URL )) {
107+ ParserTask task = new ParserTask (new StringBuilder ("https://leetcode.com" ).append (list .get (0 )).toString ());
108+ myLog .debug ("正在进行入栈操作,task的url为: " + task .getUrl ());
109+ task .isType ();
110+ queue .put (task );
111+ return ;
112+ }
106113 for (String value : list ) {
107114 ParserTask task = new ParserTask (new StringBuilder ("https://leetcode.com" ).append (value ).toString ());
108- myLog .debug ("task的url为: " + task .getUrl ());
115+ myLog .debug ("正在进行入栈操作, task的url为: " + task .getUrl ());
109116 task .isType ();
110117 queue .put (task );
111118 }
0 commit comments