I pay 70$ via paypal for a simple php script thant can:

I pay 70$ via paypal for a simple php script thant can:

1- extract images and total price from aliexpress url like:“http://fr.aliexpress.com/item/1pcs-lot-Portable-Sonar-LCD-Fish-Finder-Alarm-100M-AP-ice/410762949.html

2- echo url photos and total price extracted so I can add them to my website via php, exemple: “http://www.nejah.com/hong/index.php?ref=peche24&id=&country=

Note: I dont want to extract icons and unusufull pictures but only photos that describe item

This type of script can be done. But, it is tricky to do depending on the site the data is pulled from.

You posted this in the free area of the site. You should look into the “Freelancer” section if you want
to hire someone to do this. But, we can also help you for free if you wish.

First, is the sample URL always the same? Is it always from that one site, aliexpress.com?
If so, then it should be easy enough to create code to pull out your data. But, if it is from various
other sites, each site will be different depending on how they programmed their product pages.

Once the data is pulled out, you can save it on your server and then it can be displayed. The tricky
part is pulling the data out of their site.

So, let us know if it is always just that one company site you want to pull data from…

Thannnnnnnnnnnnks for quick replay, yess sir, only from aliexpress.

Note maybe helpfull:
Can copy image link with right mouse click “copy” only if language is french, for exemple:
http://www.aliexpress.com/item…====>>>>can not
http://fr.aliexpress.com/item…====>>> can copy images link with right mouse click “copy”

apreciate you help :slight_smile:

Okay, since you should understand what we are going to do, I will explain step by step.
It is fairly simple code. But, the digging out of what you want may be tricky.

So, first step it to capture the full page. For our talk, we will use the page you posted:
http://fr.aliexpress.com/item/1pcs-lot-Portable-Sonar-LCD-Fish-Finder-Alarm-100M-AP-ice/410762949.html

There are three steps to the process.

  1. Grab the page and store in an variable. This step easy. Below is the code to do this. Just a few
    lines of code and I have used it a lot and it is fast and works well.

  2. Decode the page and strip out the two items we want. This is done using string functions. But, the
    page coming in is complicated and we will cheat a bit to locate the data we need. This process is really
    two steps. First, we need to study the page itself and look at it’s HTML code to locate what we need and
    then figure out code that will strip out the items we do not need. Only a few lines of code once we find
    how the page is laid out.

  3. Save the picture and costs in some form that is displayable. Usually, this will be save to your database
    and the picture saved on your server. But, since you just need to display the picture, we can steal it from
    their site and in this manner, we just have to save the name and price on your site. Or, if you just want to
    display it, you can just display the values. Very little code here, too.

Now, those are the 3 simple steps. Here is step #1 which will grab that page and save it for next step:
[php]

<?php // Get a web file (HTML, XHTML, XML, image, etc.) from a URL. Return an array containing the HTTP server response header fields and content. // This is a CURL function which grabs the page for you function get_web_page( $url ) { $user_agent="Mozilla/5.0 (Windows NT 6.1; rv:8.0) Gecko/20100101 Firefox/8.0 Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36 "; $options = array( CURLOPT_CUSTOMREQUEST =>"GET", //set request type post or get CURLOPT_POST =>false, //set to GET CURLOPT_USERAGENT => $user_agent, //set user agent CURLOPT_COOKIEFILE =>"cookie.txt", //set cookie file CURLOPT_COOKIEJAR =>"cookie.txt", //set cookie jar CURLOPT_RETURNTRANSFER => true, // return web page CURLOPT_HEADER => false, // don't return headers CURLOPT_FOLLOWLOCATION => true, // follow redirects CURLOPT_ENCODING => "", // handle all encodings CURLOPT_AUTOREFERER => true, // set referer on redirect CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect CURLOPT_TIMEOUT => 120, // timeout on response CURLOPT_MAXREDIRS => 10, // stop after 10 redirects ); $ch = curl_init( $url ); curl_setopt_array( $ch, $options ); $content = curl_exec( $ch ); $err = curl_errno( $ch ); $errmsg = curl_error( $ch ); $header = curl_getinfo( $ch ); curl_close( $ch ); $header['errno'] = $err; $header['errmsg'] = $errmsg; $header['content'] = $content; return $header; } // Read the web page and check for errors: $url = "http://fr.aliexpress.com/item/1pcs-lot-Portable-Sonar-LCD-Fish-Finder-Alarm-100M-AP-ice/410762949.html"; $result = get_web_page( $url ); if ( $result['errno'] != 0 ) echo "... error: bad url, timeout, redirect loop ..."; if ( $result['http_code'] != 200 ) echo "... error: no page, no permissions, no service ..."; $page = $result['content']; ?>

[/php]
The variable $page now holds the entire page… Now for part two that will strip out what you need.
So, to find your data, I pulled up your page and used VIEW-SOURCE to see the page code. In there,
I located the price for the item in this sample. It is in a “Data-Table” and a SPAN inside of that named
with the price after the span. Easy to locate.
Therefore, to grab the price, you find that item and pull out the price. For the picture, I found it inside
the class named

  • . So, all that is needed is to pull these two out of the
    page code. This next section takes the resulting page above in the variable $page and locates these
    two items and displays them. (the above code with added lines!)
    [php]
  • <?php // Get a web file (HTML, XHTML, XML, image, etc.) from a URL. Return an array containing the HTTP server response header fields and content. // This is a CURL function which grabs the page for you function get_web_page( $url ) { $user_agent="Mozilla/5.0 (Windows NT 6.1; rv:8.0) Gecko/20100101 Firefox/8.0 Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36 "; $options = array( CURLOPT_CUSTOMREQUEST =>"GET", //set request type post or get CURLOPT_POST =>false, //set to GET CURLOPT_USERAGENT => $user_agent, //set user agent CURLOPT_COOKIEFILE =>"cookie.txt", //set cookie file CURLOPT_COOKIEJAR =>"cookie.txt", //set cookie jar CURLOPT_RETURNTRANSFER => true, // return web page CURLOPT_HEADER => false, // don't return headers CURLOPT_FOLLOWLOCATION => true, // follow redirects CURLOPT_ENCODING => "", // handle all encodings CURLOPT_AUTOREFERER => true, // set referer on redirect CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect CURLOPT_TIMEOUT => 120, // timeout on response CURLOPT_MAXREDIRS => 10, // stop after 10 redirects ); $ch = curl_init( $url ); curl_setopt_array( $ch, $options ); $content = curl_exec( $ch ); $err = curl_errno( $ch ); $errmsg = curl_error( $ch ); $header = curl_getinfo( $ch ); curl_close( $ch ); $header['errno'] = $err; $header['errmsg'] = $errmsg; $header['content'] = $content; return $header; } // Read the web page and check for errors: $url = "http://fr.aliexpress.com/item/1pcs-lot-Portable-Sonar-LCD-Fish-Finder-Alarm-100M-AP-ice/410762949.html"; $result = get_web_page( $url ); if ( $result['errno'] != 0 ) echo "... error: bad url, timeout, redirect loop ..."; if ( $result['http_code'] != 200 ) echo "... error: no page, no permissions, no service ..."; $page = $result['content']; // We now have the page, locate the picture and price inside it $start = strpos($page, '
  • ') + 34; // This item plus the length of it... $end = strpos($page, "", $start) - 2; // This item minus one for end of previous item... $picture = substr($page, $start, $end-$start); // Place this text into <>'s and it will display on site... echo "
    ". $picture . "
    "; // We have the picture image text, now capture the price $start = strpos($page, '') + 52; // This item plus the length of it... $end = strpos($page, "", $start); // This item minus one for end of previous item... $price = substr($page, $start, $end-$start); // Place this text into <>'s and it will display on site... echo "
    ". $price . "
    "; ?>

    [/php]
    I tested this code as-is and it works perfectly. You will just have to set this into your code as needed.
    So, test this page if you wish. It strips out the picture and text for the price and displays them both.
    (You only need the function code once per page.) Hope that helps!

  • Thanks a lot Dear
    I put the script in “test.php” but didnt work in my server,
    please check : http://www.nejah.com/test.php

    best regards

    see error message


    error.JPG

    Sorry, remove the first blank line. If you use a blank line at the top, it is sent to the browser
    before PHP takes over and sometimes causes a problem.

    I tested it as-is and it works on my GoDaddy.com server… But, mine did not start with a blank line.

    Let us know if that works…

    same problem :-[


    test.txt (3.33 KB)

    my server is: justhost !

    Are you using this on a server or on a local machine?

    And, don’t send by attachment, just post it inline using the PHP tags.
    It’s a lot easier to view it in the message instead of going outside to another app…

    Well, I just loaded it again to my server and ran it. I get the picture and price perfectly.

    Post the code in a message here so we can see it again…
    (To make sure there is nothing different than my version!)

    [php]<?php
    // Get a web file (HTML, XHTML, XML, image, etc.) from a URL. Return an array containing the HTTP server response header fields and content.
    // This is a CURL function which grabs the page for you
    function get_web_page( $url )
    {
    $user_agent="Mozilla/5.0 (Windows NT 6.1; rv:8.0) Gecko/20100101 Firefox/8.0 Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36 ";

         $options = array(
    
             CURLOPT_CUSTOMREQUEST  =>"GET",        //set request type post or get
             CURLOPT_POST           =>false,        //set to GET
             CURLOPT_USERAGENT      => $user_agent, //set user agent
             CURLOPT_COOKIEFILE     =>"cookie.txt", //set cookie file
             CURLOPT_COOKIEJAR      =>"cookie.txt", //set cookie jar
             CURLOPT_RETURNTRANSFER => true,     // return web page
             CURLOPT_HEADER         => false,    // don't return headers
             CURLOPT_FOLLOWLOCATION => true,     // follow redirects
             CURLOPT_ENCODING       => "",       // handle all encodings
             CURLOPT_AUTOREFERER    => true,     // set referer on redirect
             CURLOPT_CONNECTTIMEOUT => 120,      // timeout on connect
             CURLOPT_TIMEOUT        => 120,      // timeout on response
             CURLOPT_MAXREDIRS      => 10,       // stop after 10 redirects
         );
    
         $ch      = curl_init( $url );
         curl_setopt_array( $ch, $options );
         $content = curl_exec( $ch );
         $err     = curl_errno( $ch );
         $errmsg  = curl_error( $ch );
         $header  = curl_getinfo( $ch );
         curl_close( $ch );
    
         $header['errno']   = $err;
         $header['errmsg']  = $errmsg;
         $header['content'] = $content;
         return $header;
     }
    

    // Read the web page and check for errors:
    $url = “http://fr.aliexpress.com/item/1pcs-lot-Portable-Sonar-LCD-Fish-Finder-Alarm-100M-AP-ice/410762949.html”;

    $result = get_web_page( $url );

    if ( $result[‘errno’] != 0 ) echo “… error: bad url, timeout, redirect loop …”;

    if ( $result[‘http_code’] != 200 ) echo “… error: no page, no permissions, no service …”;

    $page = $result[‘content’];

    // We now have the page, locate the picture and price inside it
    $start = strpos($page, ‘

  • ’) + 34; // This item plus the length of it…
    $end = strpos($page, “
    ”, $start) - 2; // This item minus one for end of previous item…
    $picture = substr($page, $start, $end-$start); // Place this text into <>'s and it will display on site…

    echo “
    ”. $picture . “
    ”;

    // We have the picture image text, now capture the price
    $start = strpos($page, ‘’) + 52; // This item plus the length of it…
    $end = strpos($page, “
    ”, $start); // This item minus one for end of previous item…
    $price = substr($page, $start, $end-$start); // Place this text into <>'s and it will display on site…

    echo “
    ”. $price . “
    ”;
    ?>[/php]
    ** edited to add the php tags and fix the extreme amount of extra spaces in there

  • here is in txt file


    test.txt (3.33 KB)

    Okay, again… You have to learn how to post here. When you want to show code to us,
    first press enter to get to a new line. Then, press the PHP button which will give you the
    PHP tags. They will look like this:
    You enter your code between these two tags and they will look like this:
    [php]some code here[/php]
    In this manner, we can press SELECT and the code is copied directly into our clipboard and
    we can paste it into our site for testing.

    This code works on all three browser that I have here and it work on my local WAMP system, too.
    So, I am sure it is something on your server. Here is a new version. I added support for displaying
    ALL PHP errors at the top. Perhaps this will show up what is wrong on your server. Let us know!
    [php]

    <?PHPerror_reporting(E_ALL); ini_set('display_errors', 1); // Get a web file (HTML, XHTML, XML, image, etc.) from a URL. Return an array containing the HTTP server response header fields and content. // This is a CURL function which grabs the page for you function get_web_page( $url ) { $user_agent="Mozilla/5.0 (Windows NT 6.1; rv:8.0) Gecko/20100101 Firefox/8.0 Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36 "; $options = array( CURLOPT_CUSTOMREQUEST =>"GET", //set request type post or get CURLOPT_POST =>false, //set to GET CURLOPT_USERAGENT => $user_agent, //set user agent CURLOPT_COOKIEFILE =>"cookie.txt", //set cookie file CURLOPT_COOKIEJAR =>"cookie.txt", //set cookie jar CURLOPT_RETURNTRANSFER => true, // return web page CURLOPT_HEADER => false, // don't return headers CURLOPT_FOLLOWLOCATION => true, // follow redirects CURLOPT_ENCODING => "", // handle all encodings CURLOPT_AUTOREFERER => true, // set referer on redirect CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect CURLOPT_TIMEOUT => 120, // timeout on response CURLOPT_MAXREDIRS => 10, // stop after 10 redirects ); $ch = curl_init( $url ); curl_setopt_array( $ch, $options ); $content = curl_exec( $ch ); $err = curl_errno( $ch ); $errmsg = curl_error( $ch ); $header = curl_getinfo( $ch ); curl_close( $ch ); $header['errno'] = $err; $header['errmsg'] = $errmsg; $header['content'] = $content; return $header; } // Read the web page and check for errors: $url = "http://fr.aliexpress.com/item/1pcs-lot-Portable-Sonar-LCD-Fish-Finder-Alarm-100M-AP-ice/410762949.html"; $result = get_web_page( $url ); if ( $result['errno'] != 0 ) echo "... error: bad url, timeout, redirect loop ..."; if ( $result['http_code'] != 200 ) echo "... error: no page, no permissions, no service ..."; $page = $result['content']; // We now have the page, locate the picture and price inside it $start = strpos($page, '
  • ') + 34; // This item plus the length of it... $end = strpos($page, "", $start) - 2; // This item minus one for end of previous item... $picture = substr($page, $start, $end-$start); // Place this text into <>'s and it will display on site... echo "
    ". $picture . "
    "; // We have the picture image text, now capture the price $start = strpos($page, '') + 52; // This item plus the length of it... $end = strpos($page, "", $start); // This item minus one for end of previous item... $price = substr($page, $start, $end-$start); // Place this text into <>'s and it will display on site... echo "
    ". $price . "
    "; ?>

    [/php]

  • WAIT !

    Did you say TXT file??? PHP files are PHP files, like test.php NOT test.txt

    I know, just because I cant upload php files ;D
    please let me see the url you test it on godaddy.
    please send me the script in text file and I will change extention
    I’m really confused >:(

    Here is my version that works as a text file…

    I can show you the live site, but, it is a private server and just shows the one small picture and price.
    (Not much to see!)


    test.txt (3.2 KB)

    I will try to solve this problem, meanwhile, I need please to get pictures that descripe item and not small picture so I can put in my page exp: http://www.nejah.com/hong/index.php?ref=peche24&id=&country=

    I can get it to pull anything you want out of the page.

    Let’s see why your server is not showing it first.

    Try that text version renaming to PHP and let us know…

    ok Great thanks, I dont know how to thanks you for your precious help :smiley:

    Sponsor our Newsletter | Privacy Policy | Terms of Service