-1
아래 스크립트는 내 DOM 스크래퍼에 사용할 특정 URL의 전체 링크 목록을 가져옵니다. 그러나 목록 중 일부는 1000s에 들어갈 수 있으므로 어떤 링크를 실제로 잡을 지 수동으로 설정할 수 있기를 원합니다. 마치 50 번 링크에서 시작하여 100 번 목록에서 끝나기를 원합니다. 내가 어떻게 그럴 수 있니? 루프가 어디 이제까지이 추가정의 된 범위의 배열을 대상으로 지정하는 방법
<form action="" method="POST">
<label>Url to scrape: </label>
<input type="text" name="url_scrape" id="url-scrape" />
<input type="submit" value=" Scrape now " />
<br />
<input type="hidden" name="scrape" value="yes" />
<br />
</form>
<br />
<br />
<?php
if($_POST['scrape'] != 'yes')
return;
include('simple_html_dom.php');
function strim($input){
$st = explode('$', $input);
return (float)str_replace(array(' ',','),array('',''), $st[1]);
}
$url_scrape = $_POST['url_scrape'];
if($url_scrape == '')
return;
$BrowsebyLetter = file_get_html($url_scrape);
$links = $BrowsebyLetter->find('.Results a');
?>
<h1 id="patient">Please be patient while scraping data</h1>
<div id="scrape-progress">
<div id="scrape-progress-ctx">0%</div>
</div>
<br />
<br />
<br />
<div id="progress-txt"></div>
<br />
<br />
<button id="retry" onclick="iframe.src = ">Retry if not continue</button>
<iframe src="" id="cacheLoad"></iframe>
<script type="text/javascript">
var total = <?php echo count($links); ?>;
var ctx = document.getElementById('scrape-progress-ctx');
var iframe = document.getElementById('cacheLoad');
var prx = document.getElementById('progress-txt');
var pt = document.getElementById('patient');
var retry = document.getElementById('retry');
var currentLink = '';
var links = [
<?php
foreach($links as $link){
echo "'".$link->href."',";
}
?>'Complete scrape <?php echo count($links); ?> links' ];
function progress(cur){
ctx.style.width = Math.ceil((cur/total)*100)+'%';
ctx.innerHTML = Math.ceil((cur/total)*100)+'%';
};
function exe(i){
progress(i);
if(links[i] != 'Complete <?php echo count($links); ?> links')
{
currentLink = window.location+'&target='+links[i].split('Job=')[1]+'&cou='+(i+1);
iframe.src = currentLink;
};
if(i==total){
pt.innerHTML = 'Successful';
pt.style.color = 'green';
retry.style.display = 'none';
alert('Scrape process is complete');
};
prx.innerHTML = '<strong>Status: </strong>'+ links[i];
};
exe(0);
</script>