1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

how to use php cUrl to search and get image from amazon.com

Discussion in 'PHP' started by y2k4ever, May 29, 2008.

  1. #1
    Hi guys,

    I wanted to use the cUrl function and get image url from amazon.com
    so this is how it going to be:

    1. Search the music by artist and album's name (eg. Fall out boy - Infinity on high)
    2. Grasp the album's image url from the first result
    3. Insert that image url into my database.

    How do i do that? Or is there anywhere that i can look?
     
    y2k4ever, May 29, 2008 IP
  2. y2k4ever

    y2k4ever Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    i know it's not 24 hours since i last posted but anyone?
     
    y2k4ever, May 29, 2008 IP
  3. cornetofreak

    cornetofreak Peon

    Messages:
    170
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #3
    u can use preg n match to specifiy what you want then use arrays to to feed the information to your databes for other use somewhere else

    say if you had a div with a class of images, somthin like <DIV CLASS="amazon_imges">the image detals here< /DIV>

    preg_match (/<DIV CLASS="amazon_imges">(.*)< \/DIV>/,$curlvar, $output)

    then add $output[0] to your database

    look into it
     
    cornetofreak, May 31, 2008 IP
  4. rudeturk

    rudeturk Well-Known Member

    Messages:
    884
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    120
    #4
    <?php
    
    $artist = "Kanye West";
    $album = "Graduation";
    
    $artist = str_replace(' ','+',$artist);
    $album = str_replace(' ', '+', $album);
    
    $url = "http://www.amazon.com/gp/search/?search-alias=popular";
    // add artist
    $url .= "&field-artist=" . $artist;
    // add title
    $url .= "&field-title=" . $album;
    // add the rest
    $url .= "&sort=relevancerank";
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 4);
    curl_setopt($ch, CURLOPT_URL, $url);   
    $html = curl_exec($ch);
    
    // the html of the search result page is now contained within the variable $html
    PHP:
    Do something with Preg_match i dont have time to build the full function but it will be easy i hope next poster does it heres a hint:
    1-1"> <img src="(.*)" class=""
    PHP:
    Can anyone help me with my situation btw:
    http://forums.digitalpoint.com/showthread.php?t=866142
     
    rudeturk, May 31, 2008 IP
  5. y2k4ever

    y2k4ever Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    i'll get started
     
    y2k4ever, Jun 4, 2008 IP
  6. y2k4ever

    y2k4ever Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Ok i got a problem with preg_match already when there is both quote (") and apostrophe(') in $html

    some search result return different html
    for instance, this is in the html

    
    1-1"> <img onload="if (typeof uet =='function') { uet('af'); }" src="http://g-ecx.images-amazon.com/images/G/01/x-locale/common/transparent-pixel._V42752373_.gif" class=""
    
    Code (markup):
    now how do i use preg_match to match that? it has both quote and apostrophe in it therefore, i decided to use backslash \' but it didn't work

    
    if(preg_match('/1-1"> <img onload="if (typeof uet ==\'function\') { uet(\'af\'); }" src="(.*)" class=""/', $html, $d_link))
    {
    	echo "working";
    }
    else
    {
    	echo "nothing working";
    }
    
    PHP:
     
    y2k4ever, Jun 4, 2008 IP