Также этот подход подойдет и для скачивания обычный файлов (или страниц) из обычного интернета.
Нам понадобится сервер с установленным TOR и php с curl.
Также этот подход подойдет и для скачивания обычный файлов (или страниц) из обычного интернета.
Нам понадобится сервер с установленным TOR и php с curl.
Для начала, предположим, что сервер с php у нас есть и он на Centos.
yum -y install tor |
service tor start |
1 |
$ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_PROXY, '127.0.0.1:9050'); curl_setopt($ch, CURLOPT_URL, "http://domen.ru/"); curl_setopt($ch, CURLOPT_PROXYTYPE, 7); $result = curl_exec($ch); if(!$result) { echo curl_error($ch); } else { echo $result; } curl_close($ch); |
1 |
error_reporting(E_ALL); ini_set('display_errors', 'On'); class soMain { protected $_oCURL = NULL; protected $_sSite = NULL; protected $_sURL = NULL; function __construct($sSite, $sURL) { $this->_oCURL = curl_init(); $this->_sSite = $sSite; $this->_sURL = $sURL; curl_setopt($this->_oCURL, CURLOPT_RETURNTRANSFER, true); curl_setopt($this->_oCURL, CURLOPT_PROXY, '127.0.0.1:9050'); curl_setopt($this->_oCURL, CURLOPT_PROXYTYPE, 7); } protected function _getPageContent($sURL) { curl_setopt($this->_oCURL, CURLOPT_URL, $sURL); $Res = curl_exec($this->_oCURL); if($Res === false) { echo ('<b style="color :red">Ошибка curl:</b> ' . curl_error($this->_oCURL)) .'<br />'; } else { return $Res; } } protected function _parseImg($sText) { //$sTag = '<a href='; $sTag = '<img src='; $sPattern = "|"; $sPattern .= $sTag.'".*?"'; $sPattern .= '".*?"'; //$sPattern .= "|si"; $sPattern .= "|"; preg_match_all($sPattern, $sText, $aMatches, PREG_SET_ORDER); $aRet = array(); foreach($aMatches as $aMatche) { $aRet[] = str_replace('"', '', str_replace($sTag.'"', '', $aMatche[0])); } return $aRet; } protected function _downloadImg($aImages) { foreach($aImages as $sImage) { $sFileUrl = $this->_sSite.$sImage; $Res = $this->_getPageContent($sFileUrl); $sFN = str_replace('/', '_', $sImage); file_put_contents('tmp/'.$sFN, $Res); } } public function go() { ob_start(); $sPageContent = $this->_getPageContent($this->_sURL); $aImages = $this->_parseImg($sPageContent); $this->_downloadImg($aImages); ?> <? return ob_get_clean(); } } //---------------------------------------------- $sURL = 'http://domen.ru/'; for ($i=1; $i < 10; $i++) { $sURL = $sSite.'/page/'.$i.'.html'; $oMain = new soMain($sSite, $sURL); echo $oMain->go(); } |
function getContent($sUrl)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_PROXY, '127.0.0.1:9050');
curl_setopt($ch, CURLOPT_URL, $sUrl);
curl_setopt($ch, CURLOPT_PROXYTYPE, 7);
$result = curl_exec($ch);
if(!$result)
{
echo curl_error($ch);
}
curl_close($ch);
return($result);
}
$sText = getContent('http://TEST.onion/3976.html');
//echo strlen($sText)."\n";
//file_put_contents('out.html', $sText);
//$sText = file_get_contents('out.html');
$sPattern = '|Файл: <a href="(.*?)">|si';
preg_match_all($sPattern, $sText, $aMatches, PREG_SET_ORDER);
$i = 0;
$iTotal = count($aMatches);
foreach($aMatches as $aMatche)
{
$i++;
echo $i.' / '.$iTotal."\n";
file_put_contents($i.'-'.basename($aMatche[1]),
getContent('http://TEST.onion/'.$aMatche[1])
);
}