curl loop

Discussion in 'PHP' started by mbk, Nov 20, 2009.

  1. #1
    Hi all,

    I need to create a curl loop that increments and uses the increment to access pages.

    URL of www.blah.com/index.asp?p=1
    Code (markup):
    The number changes for each post on the site and some posts dont exist, ie p=4 doesnt exist it just brings a message up saying Post you are looking for doesnt exist.

    So what I need to do is have a script that takes the base URL upto = and then increment the counter each time but also if the page comes back post doesnt exist then skip this...

    Can anyone help pls?

    thanks
     
    mbk, Nov 20, 2009 IP
  2. gabibeowulfx

    gabibeowulfx Active Member

    Messages:
    211
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    63
    #2
    $i=1;
    $exit=0;

    while($exit<1) {
    curl_init("http://www.blah.com/index.asp?p=".$i);
    //other curl stuff
    //get html from curl in $data variable
    $data=curl_execute();

    //work data variable and extract useful information

    // if condition - if in $data variable you find a text that indicates
    // no more useful data can be found -> you reached the end of your
    // increments than you do $exit =1; -> it will end the loop

    sleep(5); //you don't want to make hundreds and thousands of requests
    // without letting your target take its breath. You'll get noticed and banned fast.
    $i++;
    }
     
    gabibeowulfx, Nov 21, 2009 IP
  3. mbk

    mbk Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks very much for that, greatly appreciated! :)
     
    mbk, Nov 22, 2009 IP