Skip to content

Commit

Permalink
LugMap.it: sistemato script costruzione OPML per Planet
Browse files Browse the repository at this point in the history
Grazie a Cristiano Longo per implementazione e test
  • Loading branch information
madbob committed May 1, 2017
1 parent ce66967 commit acc8933
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions forge/opml-generator/find_feeds.php
Expand Up @@ -39,6 +39,24 @@ function check_url ($url) {
return $url;
}

/**
* Download a web page using curl. Some pages return 403 forbidden using loadHTMLFile,
* whereas they are loaded with no trouble using cURL (probably the matter is related
* with HTTP headers in the post request.
*
* @return the page as string, FALSE if some error occurred
* @author Cristiano Longo
*/
function downloadPage($url){
$s = curl_init();

curl_setopt($s,CURLOPT_URL,$url);
curl_setopt($s,CURLOPT_RETURNTRANSFER,true);
$page=curl_exec($s);
curl_close($s);
return $page;
}

libxml_use_internal_errors(true);

$elenco_regioni = array (
Expand Down Expand Up @@ -84,10 +102,13 @@ function check_url ($url) {
foreach ($lugs as $lug) {
list ($prov, $name, $zone, $site) = explode ('|', $lug);
$site = check_url ($site);

$page = downloadPage($site);
if (!$page)
continue;

$doc = new DOMDocument();
$doc->loadHTMLFile($site);

$doc->loadHTML($page);
$xpath = new DOMXpath($doc);
if ($xpath == null)
continue;
Expand Down

0 comments on commit acc8933

Please sign in to comment.