1
문제가 있습니다. 공개 법인 사이트에서 일부 데이터를 긁어 내기위한 페이지를 만들었습니다. 그들의 사이트는 사용면에서 이것을 금지하지 않습니다. 그것은 어쨌든 공용 데이터입니다. 나는 이것을 위해 아래쪽이고 더러운 페이지를 썼다는 것을 안다.하지만 나는 왜 그것이 계속 반복되는지를 알 수 없다. 내 문제는 실제 스크랩 코드를 실행하기 위해 만든 템플릿 페이지가 계속 실행되는 것입니다. 그것은 계속해서 다시 시작됩니다. 코드는 다음과 같습니다.Wordpress PHP 템플릿 페이지가 계속 반복됩니다.
<?php
/*
Template Name: Scraping template
*/
$strFile = $_GET['scrape'];
$intNumOfRec = 0;
$intNumOfErr = 0;
$intHeaderLine = '';
function fnLogger ($strLine) {
$hdlLogFile = fopen("ScrapingLogFile","a") or die("Unable to open file!");
fwrite($hdlLogFile,$strLine."\r\n");
fclose($hdlLogFile);
return;
}
function fnProcessMcr() {
global $wpdb,$intNumOfRec,$intNumOfErr;
$intRecChunk = '50';
$strQuery = 'SELECT * FROM frg_subdivision_index WHERE authority is null limit '.$intRecChunk.';';
$objQuery = $wpdb->get_results($strQuery);
echo $strQuery.'</br>';
fnLogger($strQuery);
foreach($objQuery as $index=>$row)
{
fnLogger($row->id.' ');
if(strlen($row->book) !== 0 && strlen($row->map) !== 0 && strlen($row->begin) !== 0)
{
$url = '[url withheld]?q='.$row->book.'-'.$row->map.'-'.$row->begin;
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_ENCODING, "gzip");
$data = curl_exec($ch);
curl_close($ch);
$intCheckIndex = stripos($data,'<td class="right aligned"><h3 class="ui huge basic header">');
if(!$intCheckIndex)
{
//echo $row->id.': Could not find type prefix.';
$strType = 'Unknown';
$strJurisdiction = 'Unknown';
$intNumOfErr++;
}
else
{
$data = substr($data,$intCheckIndex+59);
$intCheckIndex = stripos($data,'<strong>[CANCELLED]</strong>');
$strType = "";
if($intCheckIndex !== false) {
$data = substr($data,$intCheckIndex+28);
$strType = 'Cancelled ';
}
$strType .= trim(substr($data,0,stripos($data,'Parcel')-1));
$data = substr($data,stripos($data,'Local Jurisdiction</td>')+23);
$data = substr($data,stripos($data,'<td>')+4);
$strJurisdiction = ucwords(strtolower(trim(substr($data,0,stripos($data,'<')))));
//echo ($index+$intBegRec).': Type is: '.$strType.' in '.$strJurisdiction;
$intNumOfRec++;
}
}
else
{
echo $row->id.': Missing book, map or begin.</br>';
$strType = 'Unknown';
$strJurisdiction = 'Unknown';
$intNumOfErr++;
}
$strUpdateResults = $wpdb->update('frg_subdivision_index',array(
'type' => $strType,
'authority' => $strJurisdiction),
array(
'id' => $row->id));
echo $row->id.': Type: '.$strType.' Authority:'.$strJurisdiction;
if($strUpdateResults === false)
{
echo ': ERROR update database.</br>';
$intNumOfErr++;
}
else
{
echo '</br>';
}
}
echo "</br></br>Number of records updated was: ".$intNumOfRec.'</br>';
echo "Number of errors was: ".$intNumOfErr.'</br>';
return;
}
switch ($strFile) {
case 'mcr':
fnLogger('Entered Switch Case mcr');
fnProcessMcr();
break;
case 'mcrunknown':
fnProcessMcrUnknown();
break;
default:
fnChangeTo404();
}
?>
여기에 로그 파일의 출력이 나와 있으므로 무엇을하는지 볼 수 있습니다.
Entered Switch Case mcr
SELECT * FROM frg_subdivision_index WHERE authority is null limit 50;
30729
30730
30731
30732
30733
30734
30735
30736
30737
30738
30739
30740
30741
30742
30743
30744
30745
30746
30747
30748
30749
30750
30751
30752
30753
30754
30755
30756
30757
30758
30759
30760
30761
30762
30763
30764
30765
30766
30767
30768
Entered Switch Case mcr
SELECT * FROM frg_subdivision_index WHERE authority is null limit 50;
30768
30769
30769
30770
30770
30771
30771
30772
30772
30773
30773
30774
30774
30775
30775
30776
30776
30777
30777
30778
30778
30779
30780
30781
30782
30783
30784
30785
30786
30787
30788
30789
30790
30791
30792
30793
30794
30795
30796
30797
30798
30799
30800
30801
30802
30803
30804
30805
30806
30807
30808
Entered Switch Case mcr
SELECT * FROM frg_subdivision_index WHERE authority is null limit 50;
30808
30809
30809
30810
30810
30811
30811
30812
30812
30813
30813
30814
30814
30815
30815
30816
30816
30817
30817
30818
30819
30820
30821
30822
30823
30824
30825
30826
30827
30828
30829
30830
Entered Switch Case mcr
SELECT * FROM frg_subdivision_index WHERE authority is null limit 50;
30830
30831
30831
30832
30832
30833
30833
30834
30834
30835
30835
30836
30836
30837
30837
30838
30838
30839
30839
30840
30840
30841
30841
Entered Switch Case mcr
SELECT * FROM frg_subdivision_index WHERE authority is null limit 50;
30841
30842
아무도 단서가 왜 돌아 오는 걸까요?
글쎄, 들여 쓰기가 복사 붙여 넣기에 올바르게 적용되지 않았습니다. 이 게시물에있는대로 코드를 살펴 봤는데 코드에있는 것과 다릅니다. 내 코드가 제대로 들여 쓰기되어 있고 문제가 보이지 않습니다. – RyanF
그리고 한 달 전에, 10 년 전만하더라도 AMX 컨트롤 시스템을 프로그래밍 한 경험이 거의 없었습니다. 지난 몇 주 전까지는 HTML, CSS, JS, JQuery, Bootstrap, SQL, Wordpress 또는 PHP에 대한 경험이 거의 없었습니다. 그래서 지역 사회가 저에게 줄 수있는 도움에 크게 감사 드리며, 최소한의 경각심을 유지하고 싶습니다. – RyanF