Jump to content

No output displayed even though there's no error on my code


Ricardo123

Recommended Posts

Example of it would be here:

 

website: http://bit.ly/1C0IfkY

 

Selected Source I only want to get

<p data-iceapc="3" data-iceapw="6"><span data-iceapw="2" style="font-size:25px; color:#98293D;">11am: 2-0-7 </span>

<span data-iceapw="2" style="font-size:25px; color:#98293D;">4pm: 7-2-3 </span>

<span data-iceapw="2" style="font-size:25px; color:#98293D;">9pm: __ </span></p>

Here's my code

$dom = new DOMDocument();
$dom->loadHTML($Url);
    $xpath = new DomXPath($dom);
$nodes = $xpath->query('//span[@style="font-size:25px; color:#98293D"]');
foreach ($nodes as $node) {
    echo  $node->nodeValue;
}
Link to comment
Share on other sites

loadHTML expects the HTML contents, not a url to a webpage. You need to first get the contents of the webpage (using file_get_contents) and then pass that to loadHTML

$HTML = file_get_contents($Url); // get the html contents of the webpage
$dom->loadHTML($HTML); // pass the webpage contents to loadHTML

I managed to get the values of the three span element using this path query

$nodes = $xpath->query('//span[@style="font-size:25px; color:#98293D;"]');
Edited by Ch0cu3r
Link to comment
Share on other sites

Heres the updated code

<?php
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1); 
error_reporting(E_ALL);

$html = file_get_contents("http://www.philippinepcsolotto.com/results/swertres-results");
$dom = new DOMDocument();
$dom->loadHTML($html);
    $xpath = new DomXPath($dom);
$nodes = $xpath->query('//span[@style="font-size:25px; color:#98293D"]');
foreach ($nodes as $node) {
    echo  $node->nodeValue;
}

?>
 
Now after adding new code and revising it errors pops out here is it


PHP Error Message

Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: Namespace prefix xmlns of attribute fb is not defined in Entity, line: 3 in /home/a8880105/public_html/try.php on line 12


PHP Error Message

Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: Tag header invalid in Entity, line: 182 in /home/a8880105/public_html/try.php on line 12


PHP Error Message

Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: Tag nav invalid in Entity, line: 195 in /home/a8880105/public_html/try.php on line 12


PHP Error Message

Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: Unexpected end tag : p in Entity, line: 222 in /home/a8880105/public_html/try.php on line 12

PHP Error Message

Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: Tag article invalid in Entity, line: 224 in /home/a8880105/public_html/try.php on line 12

PHP Error Message

Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: Tag header invalid in Entity, line: 225 in /home/a8880105/public_html/try.php on line 12

PHP Error Message

Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: Unexpected end tag : a in Entity, line: 233 in /home/a8880105/public_html/try.php on line 12


PHP Error Message

Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: Tag aside invalid in Entity, line: 316 in /home/a8880105/public_html/try.php on line 12


PHP Error Message

Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: Opening and ending tag mismatch: div and center in Entity, line: 496 in /home/a8880105/public_html/try.php on line 12


PHP Error Message

Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: Tag footer invalid in Entity, line: 503 in /home/a8880105/public_html/try.php on line 12



PHP Error Message

Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: Unexpected end tag : a in Entity, line: 716 in /home/a8880105/public_html/try.php on line 12
Help anyone.
Link to comment
Share on other sites

Add

libxml_use_internal_errors (true);

Before the use of loadHTML

 

Also you need to add the semi-colon after  color:#98293D  otherwise it will not find the span tag.

$nodes = $xpath->query('//span[@style="font-size:25px; color:#98293D;"]'); // semi-colon added after color:#98293D
Link to comment
Share on other sites

Thank you guys the script is now runnig. I love how fast these guys and members response to questions about php

 

Thank you so much.

 

I try using before libxml function(true)

then after loadhtml libxml (false)

which didnt work

so I try these and its a magic it works.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.