Skip to content

Commit

Permalink
Fix CodeForces crawler, 51isoft/bnuoj#18
Browse files Browse the repository at this point in the history
  • Loading branch information
crccw committed Jul 20, 2016
1 parent cd58d21 commit 39ba65b
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions functions/pcrawlers.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,30 @@ function pcrawler_insert_problem($ret,$vname,$vid) {
return $gnum;
}

function init_result() {
return array(
"title"=>"",
"description"=>"",
"input"=>"",
"output"=>"",
"sample_in"=>"",
"sample_out"=>"",
"hint"=>"",
"source"=>"",
"author"=>"",
"memory_limit"=>"",
"time_limit"=>"",
"special_judge_status"=>"",
"case_time_limit"=>"",
"vacnum"=>"",
"vtotalnum"=>""
);
}

function pcrawler_cf_one($cid,$num,$url,$ret=array(),$default_desc="") {
global $config;

$ret = init_result();
$pid=$cid.$num;
$content=get_url($url);
$content_type=get_headers($url,1)["Content-Type"];
Expand All @@ -118,8 +139,7 @@ function pcrawler_cf_one($cid,$num,$url,$ret=array(),$default_desc="") {
if (preg_match("/output<\\/div>.*<div>(<p>.*)<\\/div>/sU", $content,$matches)) $ret["description"].=trim(html_entity_decode($matches[1]));
if (preg_match("/Input<\\/div>(.*)<\\/div>/sU", $content,$matches)) $ret["input"]=trim($matches[1]);
if (preg_match("/Output<\\/div>(.*)<\\/div>/sU", $content,$matches)) $ret["output"]=trim($matches[1]);
if (preg_match("/Sample test\\(s\\)<\\/div>(.*<\\/div><\\/div>)<\\/div>/sU", $content,$matches)) $ret["sample_in"]=trim($matches[1]);
$ret["sample_out"]="";
if (preg_match("/Examples<\\/div>(.*<\\/div><\\/div>)<\\/div>/sU", $content,$matches)) $ret["sample_in"]=trim($matches[1]);
if (preg_match("/Note<\\/div>(.*)<\\/div><\\/div>/sU", $content,$matches)) $ret["hint"]=trim(html_entity_decode($matches[1]));
if (preg_match("/<th class=\"left\" style=\"width:100%;\">(.*)<\\/th>/sU", $content,$matches)) $ret["source"]=trim(strip_tags($matches[1]));
$ret["special_judge_status"]=0;
Expand Down

0 comments on commit 39ba65b

Please sign in to comment.