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.

PHP and CURL to scrap data

Discussion in 'PHP' started by Ashish Revar, Mar 14, 2014.

  1. #1
    Dear All,
    I want to download lots of papers from one site. Along with that, I need to create csv file for the details.
    http://gtuinfo.in/Engineering-Degree/ExamPapers/ExamPapers.aspx

    In this page, we need to select Branch, Semester to get exam papers.

    In my CURL method, I am able to pass semester only. I am passing all fields as per VIEWSTATE method used in that page but it doesn't work anyhow.

    My code:
    <?php

    $url = 'http://www.gtuinfo.in/Engineering-Degree/ExamPapers/ExamPapers.aspx';

    $fields = array(
    'ctl00$ContentPlaceHolder1$ddlBranch' => '7',
    'ctl00$ContentPlaceHolder1$ddlSemester' => '6',
    'ctl00$ContentPlaceHolder1$ddlExam' => '160511',
    '__EVENTTARGET' => '',
    '__EVENTARGUMENT' => '',
    '__VIEWSTATE' => '',
    'ctl00$ContentPlaceHolder1$btnSubjectResult' => 'Show',
    'ctl00$ContentPlaceHolder1$btnBranchSemesterExam' => 'Show',
    '__SCROLLPOSITIONX' => '0',
    '__SCROLLPOSITIONY' => '0',
    'ctl00$ContentPlaceHolder1$ddlSubject' => '-99',
    );

    $fields_string = "";
    foreach($fields as $key=>$value)
    {
    $fields_string .= $key.'='.$value.'&';
    }
    rtrim($fields_string, '&');
    $ch = curl_init();
    curl_setopt($ch,CURLOPT_URL, $url);
    curl_setopt($ch,CURLOPT_POST, count($fields));
    curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);

    $result = curl_exec($ch);

    curl_close($ch);

    ?>

    Please provide the solution.
     
    Ashish Revar, Mar 14, 2014 IP