Reputation: 23968
I have never used dom document and need some help.
I have tried to look at other threads and other tutorials but I can't see where I'm doing wrong.
This is the page: https://aro.lfv.se/Links/Link/ViewLink?TorLinkId=310&type=MET
Here is a smal part of the html;
<h1 class="tor-link-header">Översikt</h1>
<pre class="linkTextNormal">ÖVERSIKT FÖR OMRÅDE E UTFÄRDAD 040753
GÄLLANDE DEN 4 MAJ 2017 MELLAN 08 OCH 16 UTC
Väderöversikt
Se väderöversikt för område A+B
Sikt under 5 kilometer eller molnbas under 1000 fot
Väntas inte förekomma under perioden.
Måttlig eller svår isbildning
Väntas inte förekomma under perioden
Måttlig eller svår turbulens
08-16UTC: I hela området</pre>
<h1 class="tor-link-header">Hela Område E</h1>
<pre class="linkTextNormal">PROGNOS FÖR OMRÅDE J UTFÄRDAD 040753
GÄLLANDE DEN 4 MAJ 2017 MELLAN 08 OCH 16 UTC
I have found out that in the whole html there is only two <pre>
tags, and both of them is interesting to me.
I found this code (tweaked it slightly to fit my code) but it does not work.
$doc = new DOMDocument();
$doc->load( $URL_LHP );
$Parts = $doc->getElementsByTagName( 'pre' );
$Part = $Parts->item(0);
var_dump($Part);
foreach( $Parts as $Part ){
echo $Part;
}
The var_dump returns NULL, and echo returns nothing. $URL_LHP is the HTML in string format.
If I echo $URL_LHP it will echo the webpage but with "dead" images and no CSS.
So the variable is what I expect.
Can anyone help me with this?
Upvotes: 0
Views: 43
Reputation: 99081
This may work for you:
$html = file_get_contents("https://aro.lfv.se/Links/Link/ViewLink?TorLinkId=310&type=MET");
$dom = new DOMDocument();
@$dom->loadHTML($html);
$pres = $dom->getElementsByTagName('pre');
foreach($pres as $pre)
{
print $pre->nodeValue;
}
Ouput:
ÖVERSIKT FÖR OMRÅDE E UTFÄRDAD 040753
GÄLLANDE DEN 4 MAJ 2017 MELLAN 08 OCH 16 UTC
...
Upvotes: 1