Error In Getting Text From Another Website Using Span Id

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Dasaradh
Forum Newbie
Posts: 5
Joined: Sun Dec 07, 2014 5:19 am

Error In Getting Text From Another Website Using Span Id

Post by Dasaradh »

Hi.

I tried to get Text from another Website using Span I. I use this code

Code: Select all

$dochtml = new DOMDocument();
$dochtml->loadHTML(http://www.adcd.com/abc);  // Note the website url end does not end with ".html,.php,.htm,etc."
$elm = $dochtml->getElementById('spanid1').innerHTML;  // I tried to the get the Text of the Span Id "spanid1"
But it shows error. Can you correct the code, please ?

Thanks to all. :)
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: Error In Getting Text From Another Website Using Span Id

Post by twinedev »

After you do do the load, do you verify that the source code did properly load? Can you manually go find a span with and id of spanid1?

beyond that, without knowing what code you are working with (the source of the the other site), kind of hard to say.
Dasaradh
Forum Newbie
Posts: 5
Joined: Sun Dec 07, 2014 5:19 am

Re: Error In Getting Text From Another Website Using Span Id

Post by Dasaradh »

Thanks for the replay twinedev.

Yes. I Can find the spanid1 manually.

I will show whats on the other site..

<html>
<span id="spanid1">2.456<span>
</html>

And I tried to get that "2.456" using the code

Code: Select all

[syntax=php]$dochtml = new DOMDocument();
$dochtml->loadHTML(http://www.adcd.com/abc); 
$elm = $dochtml->getElementById('spanid1').i nnerHTML;  
But not working.
Post Reply