Grabbing text of a site

Discussion in 'Programming' started by izlik, Dec 27, 2010.

  1. #1
    Hello

    I want to grab some text of a site and i wonder How could i do this in a good way ? i only want some specific text from maybe 1-5 lines in their code with the html stripped, someone that could help me here and show and example on how this can be done ?
     
    Last edited: Dec 27, 2010
    izlik, Dec 27, 2010 IP
  2. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #2
    You could maybe try cURL
    
    $url = "http://someDomain.com";
    
    $ch = curl_init();
    curl_setopt ($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 5);
    curl_setopt ($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
    curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
    
    PHP:
    Now the variable $data holds the full page html, next you could use something like preg_match() to find what your looking for and return that as a $text = $match[0].

    If you post here or PM me with a url and the text you want, I can put together something for you.
     
    MyVodaFone, Dec 27, 2010 IP
    ThePHPMaster likes this.
  3. alex_funky_dj

    alex_funky_dj Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    or you can start with php function : file_get_contents()
     
    alex_funky_dj, Dec 28, 2010 IP