Scraping a URL

Discussion in 'PHP' started by pzn, May 28, 2006.

  1. #1
    I want to scrape a myspace IMAGE url from their Friend ID

    I assume you use $_GET, but I don't have much knowledge in PHP.
     
    pzn, May 28, 2006 IP
  2. PinoyIto

    PinoyIto Notable Member

    Messages:
    5,863
    Likes Received:
    170
    Best Answers:
    0
    Trophy Points:
    260
    #2
    maybe you can do that using the following code, but I guess it's against myspace TOS.


    This code not tested yet just direct typin here... just adjust the regular expression of no result.

    <?php
    $id="66554698"; //member id
    $u="http://profile.myspace.com/index.cfm?fuseaction=user.viewprofile&friendid=$id";
    $t = join("",file("$u"));
    
    $r = '/ctl00_Main_ctl00_UserBasicInformation1_hlDefaultImage" .*?"><img src="(.*?)"/';
    $t = ereg_replace("\n", "", $t);
    preg_match_all($r, $t, $m);
    
    
    $img=$m[1][0];
    echo "<img src='$img'>";
    ?>
    Code (markup):
     
    PinoyIto, May 28, 2006 IP
  3. pzn

    pzn Active Member

    Messages:
    575
    Likes Received:
    42
    Best Answers:
    0
    Trophy Points:
    70
    #3
    Thanks, it probably works, but my stupid host disables http wrapper.

    EDIT: it does work (tried it on a free host) Thanks a lot!
     
    pzn, May 28, 2006 IP
  4. pzn

    pzn Active Member

    Messages:
    575
    Likes Received:
    42
    Best Answers:
    0
    Trophy Points:
    70
    #4
    That's pretty lame...
     
    pzn, May 29, 2006 IP
  5. PinoyIto

    PinoyIto Notable Member

    Messages:
    5,863
    Likes Received:
    170
    Best Answers:
    0
    Trophy Points:
    260
    #5
    well I am not familiar with curl but here is why I found how to use it.... first it will get the data from the source url then save to file in your server....

    You then open the file which is save in your server using fopen, then parse it like what the first script.


    
    <?php
    $ch = curl_init("http://www.example.com/");
    $fp = fopen("example_homepage.txt", "w");
    
    curl_setopt($ch, CURLOPT_FILE, $fp);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    
    curl_exec($ch);
    curl_close($ch);
    fclose($fp);
    ?>
    
    Code (markup):
     
    PinoyIto, May 29, 2006 IP
  6. pzn

    pzn Active Member

    Messages:
    575
    Likes Received:
    42
    Best Answers:
    0
    Trophy Points:
    70
    #6
    Cool I'll try it later.
     
    pzn, May 29, 2006 IP
  7. Veselin Stoilov

    Veselin Stoilov Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    do not see fwrite or fput here

    <?php
    $ch = curl_init("http://www.example.com/");
    $fp = fopen("example_homepage.txt", "w");

    curl_setopt($ch, CURLOPT_FILE, $fp);
    curl_setopt($ch, CURLOPT_HEADER, 0);

    curl_exec($ch);
    curl_close($ch);
    fclose($fp);
    ?>
     
    Veselin Stoilov, Jun 6, 2006 IP
  8. kLdd15

    kLdd15 Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    curl is the SSL version of the php socket functions...
     
    kLdd15, Jun 6, 2006 IP