-
-
Save ronnywang/33393b0539f9e4d08c70 to your computer and use it in GitHub Desktop.
抓支付命令判決書打包的 php script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
date_default_timezone_set('Asia/Taipei'); | |
for ($i = 1; $i <= 5; $i ++) { | |
$sdate = mktime(0, 0, 0, $i, 1); | |
$edate = strtotime('+1 month', mktime(0, 0, 0, $i, 1)) - 86400; | |
while ($sdate < $edate) { | |
$year = date('Y', $edate) - 1911; | |
$file = sprintf("%d%s", $year, date('md', $edate - 86400)); | |
if (!glob("output/V-TPD-{$file}*")) { | |
break; | |
} | |
$edate -= 86400; | |
} | |
if ($sdate >= $edate) { | |
continue; | |
} | |
$sdate = date('Ymd', $sdate); | |
$edate = date('Ymd', $edate); | |
$url = "http://jirs.judicial.gov.tw/FJUD/FJUDQRY02_1.aspx?&v_court=TPD+%E8%87%BA%E7%81%A3%E8%87%BA%E5%8C%97%E5%9C%B0%E6%96%B9%E6%B3%95%E9%99%A2&v_sys=V&jud_year=&jud_case=&jud_no=&jud_title=%E6%94%AF%E4%BB%98%E5%91%BD%E4%BB%A4&keyword=&sdate={$sdate}&edate={$edate}&page=10&searchkw="; | |
error_log($url); | |
$curl = curl_init($url); | |
curl_setopt($curl, CURLOPT_REFERER, $url); | |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | |
$content = curl_exec($curl); | |
curl_close($curl); | |
if (!preg_match('#本次查詢結果共([0-9]*)筆#', $content, $matches)) { | |
throw new Exception('test'); | |
} | |
$count = $matches[1]; | |
if (!preg_match('#FJUDQRY03_1\.aspx\?id=[0-9]*&([^"]*)#', $content, $matches)){ | |
var_dump($content); | |
throw new Exception('test2'); | |
} | |
$param = $matches[1]; | |
for ($j = 1; $j <= $count; $j ++) { | |
$case_url = "http://jirs.judicial.gov.tw/FJUD/FJUDQRY03_1.aspx?id={$j}&{$param}"; | |
error_log("{$j}/{$count} {$case_url}"); | |
$curl = curl_init($case_url); | |
curl_setopt($curl, CURLOPT_REFERER, $url); | |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | |
$content = curl_exec($curl); | |
curl_close($curl); | |
if (!preg_match('#href="([^"]*)">友善列印#', $content, $matches)) { | |
var_dump($content); | |
throw new Exception('test3'); | |
} | |
$print_url = $matches[1]; | |
$query = parse_url($print_url, PHP_URL_QUERY); | |
parse_str($query, $ret); | |
/* | |
["jrecno"]=> | |
string(26) "104,司促,2243,20150130,1" | |
["v_court"]=> | |
string(28) "TPD 臺灣臺北地方法院" | |
["v_sys"]=> | |
string(1) "V" | |
["jyear"]=> | |
string(3) "104" | |
["jcase"]=> | |
string(6) "司促" | |
["jno"]=> | |
string(4) "2243" | |
["jdate"]=> | |
string(7) "1040130" | |
["jcheck"]=> | |
string(1) "1" | |
*/ | |
$court = explode(' ', $ret['v_court'])[0]; | |
$file_name = "output/{$ret['v_sys']}-{$court}-{$ret['jdate']}-{$ret['jyear']}-{$ret['jcase']}-{$ret['jno']}-{$ret['jcheck']}"; | |
file_put_contents($file_name, $content); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment