mirror of
https://github.com/manualdousuario/marreta.git
synced 2025-09-01 18:20:22 +00:00
adiciona fallback no archive.org
This commit is contained in:
parent
7a49945e1c
commit
dc29a90d49
3 changed files with 110 additions and 21 deletions
13
TEST_URLS.md
13
TEST_URLS.md
|
@ -12,7 +12,9 @@ liberation.fr
|
|||
lesoir.be
|
||||
doi.org
|
||||
utppublishing.com
|
||||
tab.uol.com.br
|
||||
chronicle.com
|
||||
latercera.com
|
||||
nexojornal.com
|
||||
|
||||
# Testados:
|
||||
## Brasil
|
||||
|
@ -41,6 +43,8 @@ https://www.folhadelondrina.com.br/folha-2/cena-musical-em-londrina-idosos-no-pa
|
|||
https://www.uol.com.br/esporte/futebol/ultimas-noticias/2024/11/20/bahia-x-palmeiras-campeonato-brasileiro-2024-rodada-34.htm
|
||||
https://www.opovo.com.br/noticias/politica/2024/11/21/atuacao-de-faccoes-nas-eleicoes-teve-compra-de-votos-e-ate-enviado-do-rj-para-intimidacoes-no-ceara.html
|
||||
https://flatout.com.br/o-impossivel-acidente-de-dan-wheldon-uma-analise-medica/
|
||||
https://tab.uol.com.br/noticias/redacao/2024/11/27/roubos-suicidios-e-assassinatos-casos-extremos-do-vicio-em-apostas.htm
|
||||
https://www.jota.info/coberturas-especiais/g20-brasil/presidente-sul-africano-quer-modelo-de-consenso-amplo-para-g20-na-era-trump
|
||||
https://*.cdn.ampproject.org/v/s/*
|
||||
|
||||
## Internacional
|
||||
|
@ -51,4 +55,9 @@ https://www.wired.com/story/waymo-robotaxi-driverless-future/
|
|||
https://www.forbes.com/sites/cyrusfarivar/2024/11/20/under-trump-tariffs-made-in-vietnam-will-be-the-new-made-in-china/
|
||||
https://observador.pt/especiais/mais-formacao-investimento-na-frota-reforco-dos-tecnicos-de-emergencia-e-autonomia-o-que-precisa-o-inem-segundo-varios-especialistas/
|
||||
https://www.businessinsider.com/bluesky-user-growth-social-coo-servers-twitter-elon-musk-x-2024-11
|
||||
https://cooking.nytimes.com/recipes/1016583-perfect-instant-ramen?smid=bsky-nytimes
|
||||
https://cooking.nytimes.com/recipes/1016583-perfect-instant-ramen?smid=bsky-nytimes
|
||||
https://www.latercera.com/nacional/noticia/gracias-por-arruinar-mi-vida-maldito-el-contenido-de-los-25-correos-que-boric-entrego-a-fiscal-que-investiga-denuncia/HL44T5EN55H6DHADGMORNCCNBY/
|
||||
https://www.liberation.fr/culture/cinema/les-nouveaux-films-de-monstres-de-plus-en-plus-repugnangnan-20241106_BMQANPKL3FEPNLFIAXP5HIUSIQ/
|
||||
https://www.washingtonpost.com/world/2024/12/03/martial-law-south-korea-explained/
|
||||
https://www.haaretz.com/israel-news/2024-12-04/ty-article-live/idf-claims-hezbollah-liaison-to-syrian-army-killed-in-damascus-airstrike/00000193-8fa5-d2e5-a9b3-bfffbbc70000
|
||||
https://www.haaretz.co.il/news/politics/2024-11-20/ty-article/.premium/00000193-4b4c-d383-abbb-ebffe90d0000
|
|
@ -8,24 +8,19 @@
|
|||
*/
|
||||
return [
|
||||
// Sites de notícias
|
||||
'wsj.com', // Hard
|
||||
'bloomberg.com', // Bloqueio
|
||||
'piaui.folha.uol.com.br', // Hard
|
||||
'jota.info', // Hard
|
||||
'haaretz.com', // Hard
|
||||
'haaretz.co.il', // Hard
|
||||
'washingtonpost.com', // Bloqueio
|
||||
'gauchazh.clicrbs.com.br', // Hard
|
||||
'barrons.com', // Bloqueio
|
||||
'economist.com', // Hard
|
||||
'liberation.fr', // Bloqueio
|
||||
'lesoir.be', // Bloqueio
|
||||
'doi.org', // Hard
|
||||
'utppublishing.com', // Hard
|
||||
'tab.uol.com.br', // Bloqueio
|
||||
'chronicle.com', // Hard
|
||||
'latercera.com', // Bloqueio
|
||||
'nexojornal.com', // Hard
|
||||
//-- Conteudo fica atras de um acesso de login
|
||||
'wsj.com',
|
||||
'piaui.folha.uol.com.br',
|
||||
'economist.com',
|
||||
'doi.org',
|
||||
'utppublishing.com',
|
||||
'chronicle.com',
|
||||
'nexojornal.com',
|
||||
'lesoir.be',
|
||||
'barrons.com',
|
||||
//-- Bloqueio tecnico de acesso ao conteudo
|
||||
'bloomberg.com',
|
||||
'gauchazh.clicrbs.com.br',
|
||||
// Tracking
|
||||
'metaffiliation.com',
|
||||
'google-analytics.com',
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
* - Resolução DNS
|
||||
* - Requisições HTTP com múltiplas tentativas
|
||||
* - Processamento de conteúdo baseado em regras específicas por domínio
|
||||
* - Suporte a Wayback Machine como fallback
|
||||
*/
|
||||
|
||||
require_once 'Rules.php';
|
||||
|
@ -188,7 +189,91 @@ class URLAnalyzer
|
|||
usleep(500000); // 0.5 segundo de espera entre tentativas
|
||||
}
|
||||
|
||||
throw new Exception("Falha ao obter conteúdo após {$this->maxAttempts} tentativas. Erros: " . implode(', ', $errors));
|
||||
// Se todas as tentativas falharem, tenta buscar do Wayback Machine
|
||||
try {
|
||||
$content = $this->fetchFromWaybackMachine($url);
|
||||
if (!empty($content)) {
|
||||
return $content;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$errors[] = "Wayback Machine: " . $e->getMessage();
|
||||
}
|
||||
|
||||
throw new Exception("Falha ao obter conteúdo após {$this->maxAttempts} tentativas e Wayback Machine. Erros: " . implode(', ', $errors));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tenta obter o conteúdo da URL do Internet Archive's Wayback Machine
|
||||
*
|
||||
* @param string $url URL original
|
||||
* @return string|null Conteúdo do arquivo ou null se falhar
|
||||
*/
|
||||
private function fetchFromWaybackMachine($url)
|
||||
{
|
||||
// Remove o protocolo (http/https) da URL
|
||||
$cleanUrl = preg_replace('#^https?://#', '', $url);
|
||||
|
||||
// Primeiro, verifica a disponibilidade de snapshots
|
||||
$availabilityUrl = "https://archive.org/wayback/available?url=" . urlencode($cleanUrl);
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_URL => $availabilityUrl,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_FOLLOWLOCATION => true,
|
||||
CURLOPT_TIMEOUT => 10,
|
||||
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
|
||||
CURLOPT_SSL_VERIFYPEER => false
|
||||
]);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
$error = curl_error($ch);
|
||||
curl_close($ch);
|
||||
|
||||
if ($error || empty($response)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$data = json_decode($response, true);
|
||||
if (!isset($data['archived_snapshots']['closest']['url'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Obtém o snapshot mais recente
|
||||
$archiveUrl = $data['archived_snapshots']['closest']['url'];
|
||||
|
||||
// Busca o conteúdo do snapshot
|
||||
$ch = curl_init();
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_URL => $archiveUrl,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_FOLLOWLOCATION => true,
|
||||
CURLOPT_MAXREDIRS => 2,
|
||||
CURLOPT_TIMEOUT => 30,
|
||||
CURLOPT_ENCODING => '',
|
||||
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
|
||||
CURLOPT_SSL_VERIFYPEER => false,
|
||||
CURLOPT_HTTPHEADER => [
|
||||
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
|
||||
'Accept-Language: en-US,en;q=0.5',
|
||||
'Cache-Control: no-cache',
|
||||
'Pragma: no-cache'
|
||||
]
|
||||
]);
|
||||
|
||||
$content = curl_exec($ch);
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
$error = curl_error($ch);
|
||||
curl_close($ch);
|
||||
|
||||
if ($error || $httpCode >= 400 || empty($content)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Remove o toolbar do Wayback Machine
|
||||
$content = preg_replace('/<!-- BEGIN WAYBACK TOOLBAR INSERT -->.*?<!-- END WAYBACK TOOLBAR INSERT -->/s', '', $content);
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue