@@ -80,53 +80,53 @@ |
||
| 80 | 80 | |
| 81 | 81 | public function crawler($con) |
| 82 | 82 | { |
| 83 | - if($con == "all") { |
|
| 84 | - return ; |
|
| 83 | + if ($con=="all") { |
|
| 84 | + return; |
|
| 85 | 85 | } |
| 86 | - $this->con = $con; |
|
| 87 | - $this->imgi = 1; |
|
| 88 | - $problemModel = new ProblemModel(); |
|
| 89 | - $res = Requests::get("http://acm.hdu.edu.cn/showproblem.php?pid={$con}"); |
|
| 90 | - if (strpos("No such problem",$res->body) !== false) { |
|
| 86 | + $this->con=$con; |
|
| 87 | + $this->imgi=1; |
|
| 88 | + $problemModel=new ProblemModel(); |
|
| 89 | + $res=Requests::get("http://acm.hdu.edu.cn/showproblem.php?pid={$con}"); |
|
| 90 | + if (strpos("No such problem", $res->body)!==false) { |
|
| 91 | 91 | header('HTTP/1.1 404 Not Found'); |
| 92 | 92 | die(); |
| 93 | 93 | } |
| 94 | - else if(strpos("Invalid Parameter.",$res->body) !== false) { |
|
| 94 | + else if (strpos("Invalid Parameter.", $res->body)!==false) { |
|
| 95 | 95 | header('HTTP/1.1 404 Not Found'); |
| 96 | 96 | die(); |
| 97 | 97 | } |
| 98 | 98 | else { |
| 99 | - $res->body = iconv("gb2312","utf-8//IGNORE",$res->body); |
|
| 100 | - $this->pro['pcode'] = "HDU".$con; |
|
| 101 | - $this->pro['OJ'] = 8; |
|
| 102 | - $this->pro['contest_id'] = null; |
|
| 103 | - $this->pro['index_id'] = $con; |
|
| 104 | - $this->pro['origin'] = "http://acm.hdu.edu.cn/showproblem.php?pid={$con}"; |
|
| 105 | - $this->pro['title'] = self::find("/<h1 style='color:#1A5CC8'>([\s\S]*?)<\/h1>/",$res->body); |
|
| 106 | - $this->pro['time_limit'] = self::find('/Time Limit:.*\/(.*) MS/',$res->body); |
|
| 107 | - $this->pro['memory_limit'] = self::find('/Memory Limit:.*\/(.*) K/',$res->body); |
|
| 108 | - $this->pro['solved_count'] = self::find("/Accepted Submission(s): ([\d+]*?)/",$res->body); |
|
| 99 | + $res->body=iconv("gb2312", "utf-8//IGNORE", $res->body); |
|
| 100 | + $this->pro['pcode']="HDU".$con; |
|
| 101 | + $this->pro['OJ']=8; |
|
| 102 | + $this->pro['contest_id']=null; |
|
| 103 | + $this->pro['index_id']=$con; |
|
| 104 | + $this->pro['origin']="http://acm.hdu.edu.cn/showproblem.php?pid={$con}"; |
|
| 105 | + $this->pro['title']=self::find("/<h1 style='color:#1A5CC8'>([\s\S]*?)<\/h1>/", $res->body); |
|
| 106 | + $this->pro['time_limit']=self::find('/Time Limit:.*\/(.*) MS/', $res->body); |
|
| 107 | + $this->pro['memory_limit']=self::find('/Memory Limit:.*\/(.*) K/', $res->body); |
|
| 108 | + $this->pro['solved_count']=self::find("/Accepted Submission(s): ([\d+]*?)/", $res->body); |
|
| 109 | 109 | $this->pro['input_type']='standard input'; |
| 110 | 110 | $this->pro['output_type']='standard output'; |
| 111 | - $this->pro['description'] = $this->cacheImage(HtmlDomParser::str_get_html(self::find("/Problem Description.*<div class=panel_content>(.*)<\/div><div class=panel_bottom>/sU",$res->body), true, true, DEFAULT_TARGET_CHARSET, false)); |
|
| 111 | + $this->pro['description']=$this->cacheImage(HtmlDomParser::str_get_html(self::find("/Problem Description.*<div class=panel_content>(.*)<\/div><div class=panel_bottom>/sU", $res->body), true, true, DEFAULT_TARGET_CHARSET, false)); |
|
| 112 | 112 | $this->pro['description']=str_replace("$", "$$", $this->pro['description']); |
| 113 | - $this->pro['input'] = self::find("/<div class=panel_title align=left>Input.*<div class=panel_content>(.*)<\/div><div class=panel_bottom>/sU",$res->body); |
|
| 113 | + $this->pro['input']=self::find("/<div class=panel_title align=left>Input.*<div class=panel_content>(.*)<\/div><div class=panel_bottom>/sU", $res->body); |
|
| 114 | 114 | $this->pro['input']=str_replace("$", "$$", $this->pro['input']); |
| 115 | - $this->pro['output'] = self::find("/<div class=panel_title align=left>Output.*<div class=panel_content>(.*)<\/div><div class=panel_bottom>/sU",$res->body); |
|
| 115 | + $this->pro['output']=self::find("/<div class=panel_title align=left>Output.*<div class=panel_content>(.*)<\/div><div class=panel_bottom>/sU", $res->body); |
|
| 116 | 116 | $this->pro['output']=str_replace("$", "$$", $this->pro['output']); |
| 117 | - $this->pro['sample'] = []; |
|
| 118 | - $this->pro['sample'][] = [ |
|
| 119 | - 'sample_input'=>self::find("/<pre><div.*>(.*)<\/div><\/pre>/sU",$res->body), |
|
| 120 | - 'sample_output'=>self::find("/<div.*>Sample Output<\/div><div.*><pre><div.*>(.*)<\/div><\/pre><\/div>/sU",$res->body) |
|
| 117 | + $this->pro['sample']=[]; |
|
| 118 | + $this->pro['sample'][]=[ |
|
| 119 | + 'sample_input'=>self::find("/<pre><div.*>(.*)<\/div><\/pre>/sU", $res->body), |
|
| 120 | + 'sample_output'=>self::find("/<div.*>Sample Output<\/div><div.*><pre><div.*>(.*)<\/div><\/pre><\/div>/sU", $res->body) |
|
| 121 | 121 | ]; |
| 122 | 122 | // $this->pro['sample']['sample_input'] = self::find("/<pre><div.*>(.*)<\/div><\/pre>/sU",$res->body); |
| 123 | 123 | // $this->pro['sample']['sample_output'] = self::find("/<div.*>Sample Output<\/div><div.*><pre><div.*>(.*)<\/div><\/pre><\/div>/sU",$res->body); |
| 124 | - $this->pro['note'] = self::find("/<i>Hint<\/i><\/div>(.*)<\/div><i style='font-size:1px'>/sU",$res->body); |
|
| 125 | - $this->pro['source'] = strip_tags(self::find("/<div class=panel_title align=left>Source<\/div> (.*)<div class=panel_bottom>/sU",$res->body)); |
|
| 126 | - if($this->pro['source'] === "") { |
|
| 127 | - $this->pro['source'] = $this->pro['pcode']; |
|
| 124 | + $this->pro['note']=self::find("/<i>Hint<\/i><\/div>(.*)<\/div><i style='font-size:1px'>/sU", $res->body); |
|
| 125 | + $this->pro['source']=strip_tags(self::find("/<div class=panel_title align=left>Source<\/div> (.*)<div class=panel_bottom>/sU", $res->body)); |
|
| 126 | + if ($this->pro['source']==="") { |
|
| 127 | + $this->pro['source']=$this->pro['pcode']; |
|
| 128 | 128 | } |
| 129 | - $this->pro['force_raw'] = 0; |
|
| 129 | + $this->pro['force_raw']=0; |
|
| 130 | 130 | $problem=$problemModel->pid($this->pro['pcode']); |
| 131 | 131 | |
| 132 | 132 | if ($problem) { |
@@ -90,12 +90,10 @@ |
||
| 90 | 90 | if (strpos("No such problem",$res->body) !== false) { |
| 91 | 91 | header('HTTP/1.1 404 Not Found'); |
| 92 | 92 | die(); |
| 93 | - } |
|
| 94 | - else if(strpos("Invalid Parameter.",$res->body) !== false) { |
|
| 93 | + } else if(strpos("Invalid Parameter.",$res->body) !== false) { |
|
| 95 | 94 | header('HTTP/1.1 404 Not Found'); |
| 96 | 95 | die(); |
| 97 | - } |
|
| 98 | - else { |
|
| 96 | + } else { |
|
| 99 | 97 | $res->body = iconv("gb2312","utf-8//IGNORE",$res->body); |
| 100 | 98 | $this->pro['pcode'] = "HDU".$con; |
| 101 | 99 | $this->pro['OJ'] = 8; |