extract link from a div

Discussion in 'PHP' started by Fracisc, Jan 2, 2014.

  1. #1
    The is an external site which has some links I want to extract. They are inside of divs with the class name "event-title".
     <div class="event-text">
    Code (markup):
    How can I do that? What's the simplest way?

    Thanks!
     
    Fracisc, Jan 2, 2014 IP
  2. Philbeng

    Philbeng Well-Known Member

    Messages:
    36
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    100
    #2
    If you want to use php for it then take a look at http://sourceforge.net/projects/simplehtmldom/?source=recommended
    They have simple to follow instructions on the site.
     
    Philbeng, Jan 2, 2014 IP
    Fracisc likes this.
  3. SubediK

    SubediK Active Member

    Messages:
    63
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    83
    #3
    <?php
    $url = 'http://www.something.com/page.html';
    $html =  new SimpleXmlElement($url, null, true);
    
    $content = $html->xpath("//div[@id='event-text']");
    
    ?>
    PHP:
    The contents of the div (the links i guess) will be stored in $content
     
    SubediK, Jan 5, 2014 IP
    Fracisc likes this.
  4. Fracisc

    Fracisc Well-Known Member

    Messages:
    3,670
    Likes Received:
    10
    Best Answers:
    1
    Trophy Points:
    195
    #4
    Thanks. I have managed to do what I needed.
     
    Fracisc, Jan 6, 2014 IP