Tweede Kamer -
nl
hourly
1
custom
custom
https://server.com/tk-zoek-rss.php?
array(
"verify_peer"=>false,
"verify_peer_name"=>false,
),
);
$body=file_get_contents("https://www.tweedekamer.nl/zoeken?qry=".urlencode($query)."&cfg=tksearch&sta=1&srt=date%3Adesc%3Adate&fld_tk_categorie=Kamerstukken", false, stream_context_create($arrContextOptions));
$doc = new DOMDocument();
@$doc->loadHTML( $body );
$xpath=new DOMXPath( $doc );
$index=1;
while ($index <10)
{
$description_query = '/html/body/div/main/div/div/div/div/div[2]/div/div['.$index.']/div/div[2]/div/div[1]/p';
$pubDate_query = '/html/body/div/main/div/div/div/div/div[2]/div/div['.$index.']/div/div[1]/div/div[2]/div/div[1]/time';
$pubDate_query_2 = '/html/body/div/main/div/div/div/div/div[2]/div/div['.$index.']/div/div[1]/div/div[2]/time';
$link_query = '/html/body/div/main/div/div/div/div/div[2]/div/div['.$index.']/div/div[2]/div/div[1]/h4/a';
$header_query = '/html/body/div/main/div/div/div/div/div[2]/div/div['.$index.']/div/div[1]/div/div[1]/h3';
$description=$xpath->query($description_query)->item(0)->nodeValue;
if (isset($xpath->query($pubDate_query)->item(0)->nodeValue))
$pubDate=dutch_date($xpath->query($pubDate_query)->item(0)->nodeValue);
else
$pubDate= dutch_date($xpath->query($pubDate_query_2)->item(0)->nodeValue);
$link=$xpath->query($link_query)->item(0)->getAttribute('href');
$title=$xpath->query($link_query)->item(0)->nodeValue;
$header=$xpath->query($header_query)->item(0)->nodeValue;
print "\t- \n";
print "\t\t".clean_up($header.": ".$title)."\n";
print "\t\thttps://www.tweedekamer.nl".str_replace("&", "&",$link)."\n";
print "\t\thttps://www.tweedekamer.nl".str_replace("&", "&",$link)."\n";
print "\t\t".clean_up($description)."\n";
print "\t\t".date("r",strtotime($pubDate))."\n";
print "\t
\n";
$index++;
}
function clean_up($subject)
{
$subject=str_replace("&","&",$subject); //was &
$subject=str_replace(">",">",$subject);
$subject=str_replace("<","<",$subject); // was <
$subject=str_replace(chr(8),"",$subject); // edge case, added dec 8th 2015 (backspace)
$subject=str_replace(array("\r", "\n"), '', $subject);
$subject = preg_replace('/\s+/', ' ', $subject); // https://stackoverflow.com/a/2326133
return trim($subject);
}
function dutch_date($datetime)
{
$datetime=trim($datetime);
$months = array(
"januari" => "01",
"februari" => "02",
"maart" => "03",
"april" => "04",
"mei" => "05",
"juni" => "06",
"juli" => "07",
"augustus" => "08",
"september" => "09",
"oktober" => "10",
"november" => "11",
"december" => "12"
);
$array = explode(" ", $datetime);
if(isset($months[strtolower($array[1])]))
$array[1] = $months[strtolower($array[1])];
else
print "error met $datetime
";
return $array[2]."-".$array[1]."-".$array[0];
}
?>