#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    27
    Rep Power
    0

    HELP -get contents using Dom Document


    I want to get the contents of tag <span class="jcn"> and <a class="ctc f13"> between below code. I want to get these both tag content as one record and save it in my database.

    <section class="jcar">
    <section class="jbc">

    <section class="jrcl">
    <p>
    Next To Goregaon Fly Over,Near Durian Estate, Goregaon East, Mumbai - 400063 |<a href="http://justdial.com/Mumbai/Hotel-Lucky-&lt;near&gt;-Next-To-Goregaon-Fly-Over-Near-Durian-Estate-Goregaon-East/022PXX22-XX22-110615104904-F8N1_TXVtYmFpIFJlc3RhdXJhbnRz_BZDET/map" title="View Hotel Lucky Map"> View Map</a><br>
    </p>

    <p><span class="Gray">Call</span><span class="f13">: </span><a class="ctc f13" href="tel:+912261634592">(022) 61634592</a></p>

    <section class="jbbg">

    <a class='jdr' href='javascript:void(0);' onClick="return openDiv('jrtp');"></a>
    <span class="jcn">
    <a href="http://justdial.com/Mumbai/Hotel-Lucky-&lt;near&gt;-Next-To-Goregaon-Fly-Over-Near-Durian-Estate-Goregaon-East/022PXX22-XX22-110615104904-F8N1_TXVtYmFpIFJlc3RhdXJhbnRz_BZDET" title='Hotel Lucky in Goregaon East, Mumbai' >Hotel Lucky</a>
    </span>

    <section class="jrat">
    <a rel="nofollow" href="http://justdial.com/Mumbai/Hotel-Lucky-&lt;near&gt;-Next-To-Goregaon-Fly-Over-Near-Durian-Estate-Goregaon-East/022PXX22-XX22-110615104904-F8N1_TXVtYmFpIFJlc3RhdXJhbnRz_BZDET#rvw"><span class='s10'></span><span class='s10'></span><span class='s10'></span><span class='s8'></span><span class='s0'></span></a>
    <a class="jrt" href="http://justdial.com/Mumbai/Hotel-Lucky-&lt;near&gt;-Next-To-Goregaon-Fly-Over-Near-Durian-Estate-Goregaon-East/022PXX22-XX22-110615104904-F8N1_TXVtYmFpIFJlc3RhdXJhbnRz_BZDET#rvw">195 ratings</a>
    <span class="jrt"> |</span>
    <a class="rate_this" onclick="_ct('ratethis','lspg');" href="http://justdial.com/Mumbai/Hotel-Lucky-&lt;near&gt;-Next-To-Goregaon-Fly-Over-Near-Durian-Estate-Goregaon-East/022PXX22-XX22-110615104904-F8N1_TXVtYmFpIFJlc3RhdXJhbnRz_BZDET/writereview">Rate this</a>
    </section>
    <section class="jcar">
    <section class="jbc">
    <a class="clogo" href="http://justdial.com/Mumbai/Hotel-Lucky-&lt;near&gt;-Next-To-Goregaon-Fly-Over-Near-Durian-Estate-Goregaon-East/022PXX22-XX22-110615104904-F8N1_TXVtYmFpIFJlc3RhdXJhbnRz_BZDET">
    <img width="83" height="56" border="0" src="http://images.jdmagicbox.com/upload_test/mumbai/n1/022pxx22.xx22.110615104904.f8n1/logo/a68f1ffd561f68faf73163827907dec5_t.jpg" class="Clogo" />
    </a>
    <section class="jrcl">
    <p>
    Next To Goregaon Fly Over,Near Durian Estate, Goregaon East, Mumbai - 400063 |<a href="http://justdial.com/Mumbai/Hotel-Lucky-&lt;near&gt;-Next-To-Goregaon-Fly-Over-Near-Durian-Estate-Goregaon-East/022PXX22-XX22-110615104904-F8N1_TXVtYmFpIFJlc3RhdXJhbnRz_BZDET/map" title="View Hotel Lucky Map"> View Map</a><br>
    </p>

    <p><span class="Gray">Call</span><span class="f13">: </span><a class="ctc f13" href="tel:+912261634592">(022) 61634592</a></p>
    </section>

    Any help is appreciated.
    Thanks.
  2. #2
  3. Mad Scientist
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2007
    Location
    North Yorkshire, UK
    Posts
    3,661
    Rep Power
    4123
    what have you got so far?

    Do you get any errors? If so, what are they?
    I said I didn't like ORM!!! <?php $this->model->update($this->request->resources[0])->set($this->request->getData())->getData('count'); ?>

    PDO vs mysql_* functions: Find a Migration Guide Here

    [ Xeneco - T'interweb Development ] - [ Are you a Help Vampire? ] - [ Read The manual! ] - [ W3 methods - GET, POST, etc ] - [ Web Design Hell ]
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    27
    Rep Power
    0
    well i want the contents between those tags.
    can some one help me out with this code?
  6. #4
  7. Mad Scientist
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2007
    Location
    North Yorkshire, UK
    Posts
    3,661
    Rep Power
    4123
    you've said you want to use DOM Document, so what code have you written yourself which uses DOM Document?

    We're not going to write the code for you, so you make a start (read the manual to help) and we'll help you on your the right track and aid you in your methodolgy
    I said I didn't like ORM!!! <?php $this->model->update($this->request->resources[0])->set($this->request->getData())->getData('count'); ?>

    PDO vs mysql_* functions: Find a Migration Guide Here

    [ Xeneco - T'interweb Development ] - [ Are you a Help Vampire? ] - [ Read The manual! ] - [ W3 methods - GET, POST, etc ] - [ Web Design Hell ]
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    27
    Rep Power
    0
    <?php

    ini_set( "display_errors", 0); //warning not to display
    $homepage = file_get_contents('http://justdial.com/Mumbai/Restaurants/ct-304085');

    $xml = '<span class="ctc jcn">Details i want to get</span>';
    $dom = new DOMDocument;
    $dom->loadHTML($homepage);
    $spans = $dom->getElementsByTagName('section');

    echo $span;


    foreach ($spans as $span) {

    if($span->getAttribute('class') == 'jcar') {



    $t=trim(strip_tags($span->nodeValue));
    echo $t;


    }
    }
    ?>


    This is my code to extract all the values between the <section> tag. But now i only want the values between the <span class="jcn"> and <a class="ctc f13">tag
  10. #6
  11. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,957
    Rep Power
    1045
    Originally Posted by priyankagound
    This is my code to extract all the values between the <section> tag. But now i only want the values between the <span class="jcn"> and <a class="ctc f13">tag
    Use XPath. It allows you to specify selectors, much like CSS.

    In your case, you'll want something like

    Code:
    //span[class="jcn"]
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    27
    Rep Power
    0
    I have gone through it but am confused how to extract contents from both the tag i my code.

IMN logo majestic logo threadwatch logo seochat tools logo