Results 1 to 6 of 6

Thread: Help parsing artist,songname and image url from remote html

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Help parsing artist,songname and image url from remote html

    Hi all there is a remote html page that has artist,songname and image url . I want to get these infromation when ever i pull that page . could any one show me how this can be done.Thanks

    Note: the information that i want to extract are shown in bold.
    Note: the html is dynamic and changes

    Html of page that i want to pull every few seconds:
    <table border=0 width="280" bgcolor="#FFFFFF" cellpadding=5><tr><td align="center" width="80">
    <a href="http://www.somesite.com" target="_blank"><img border="0" src="http://www.somesite.com/static/artists/kiosk.jpg" border="0"></a></td><td width="100" style="font-family:Arial; font-size:12px; color:#000000;">artist<br>"songname"</td><td valign="top"><table><tr><td><table><tr><td><a href="http://www.somesite.com" target="_blank"><img border="0" src="http://www.somesite.com/static/artists/rj_box.jpg" width="30" height="30" border="0"></a></td><td><font size="1" face="Arial" color="red"><b>RADIO<br>ABCDE</b></font></td></tr></table></td></tr><tr><td><a href="http://www.somesite.com/listen" target="_blank"><img border="0" src="http://www.somesite.com/images/nwp96k.gif"></a></td></tr><tr><td><a href="http://www.somesite.com/listen" target="_blank"><img border="0" src="http://www.somesite.com/images/nwp128k.gif"></a></td></tr></table></td></tr></table

  2. #2
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    Re: Help parsing artist,songname and image url from remote html

    What do you mean the HTML is dynamic and changes? Do you mean the bold values change, or does the actual page HTML change?

    If the HTML changes each time, there is no way you can write code to parse it.

    If the HTML is constant, you could use preg_match() to find instances of /static/artists/(.*).jpg and (.*)<br />"(.*)" to extract those data elements, assuming no other text in the HTML matches these patterns.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: Help parsing artist,songname and image url from remote html

    Quote Originally Posted by The Hobo
    What do you mean the HTML is dynamic and changes? Do you mean the bold values change, or does the actual page HTML change?

    If the HTML changes each time, there is no way you can write code to parse it.

    If the HTML is constant, you could use preg_match() to find instances of /static/artists/(.*).jpg and (.*)<br />"(.*)" to extract those data elements, assuming no other text in the HTML matches these patterns.
    Thanks for your reply. The html is the same only the bold parts changes. so i want the php some how pull that html page and then extract the bold data.But i don't know how to tell php to get that html and then get the bold data for me.Hope some one show me how this can be done.Thanks

    Note: the html is in remote server and i have no controle over it

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Help parsing artist,songname and image url from remote html

    Are you using PHP 5?
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: Help parsing artist,songname and image url from remote html

    Quote Originally Posted by visualAd
    Are you using PHP 5?
    Thanks for reply.The server that i want to install the script is running PHP Version 4.4.0.

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: Help parsing artist,songname and image url from remote html

    i tried this solution but it doesn't output the image url for me . could any one tell me what i am doing wrong and how to fix it.Thanks

    PHP Code:
    <?PHP
    $html 
    file_get_contents("http://services.remotesite.com/rss.php?html=280");
    preg_match("/<img border=\"0\" src=\"(.*)\" border=\"0\">$/"$html$urls);
    //preg_match("<td width=\"100\" (.*)>(.*)</td>", $html, $tdmatch);
    preg_match("/<td width=\"100\" (.*)>(.*)<\/td>/"$html$tdmatch);   

    echo 
    "<pre>";
    var_dump($urls);
    var_dump($tdmatch);
    echo 
    "</pre>";

    ?>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width