Jump to content

Scraping an aspx site with php


boosthungry

Recommended Posts

I'm looking to scrape the schedule details for any particular class at my university as part of a school project.  I have been able to log a student into the university site, grab their name and course information. 

 

In order to grab the schedule for a particular class I now have to visit a different area of the university site, the registrar.  The course schedule section of the registrar is coded in ASP .net and I'm having trouble making HTTP requests to this area of the site.

 

I understand the need to make post requests to mimic the Viewstate but I'm running into an issue before I even get to that part.

 

I am able to load the page via an HTTP request almost every time.  But it always takes almost exactly 2 minutes.  I have tried simple get requests, post requests with the Viewstate, and other variations to one of a few different pages on the site.  Each time it works.  But each time it takes 2 minutes.

 

Any ideas why it takes so long?  Any suggestions on what I can possibly do differently?

 

Here is the basic site I'm using to test my code on before implementing it fully into my program:

University Site

Here is my link that takes 2 minutes to load the same page:

My Site

 

Here is my latest code I've tried:

<?php

$postdata = "__VIEWSTATE=/wEPDwULLTIwNjY2MzUzMDEPZBYCAgUPDxYCHgRUZXh0BRNNYXIgMjMgMjAxMSAgNzoxNVBNZGQYAQUeX19Db250cm9sc1JlcXVpcmVQb3N0QmFja0tleV9fFgEFDmN0bDEwJGltZ0xvZ2luaYy4H4gz+Bjb4GVdsO1ecd9c9EA=";
$postdata .= "&__EVENTVALIDATION=/wEWAgKs/IaWBAKpyP2zAXWcNEO0tMqDX53r6m+Hzo/nKHwZ";
$postdata = urlencode($postdata);
$host = 'courseschedules.njit.edu';
$path = '/index.aspx';

$fp1 = fsockopen($host,80,$errno,$errstr,30);
if(!$fp1) 
die($_err.$errstr.$errno); 
else 
{
fputs($fp1, "POST $path HTTP/1.1\r\n");
fputs($fp1, "Host: $host\r\n");
fputs($fp1, "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.15) Gecko/20110303 Firefox/3.6.15 ( .NET CLR 3.5.30729)\r\n");
fputs($fp1, "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n");
fputs($fp1, "Accept-Language: en-us,en;q=0.5\r\n");
fputs($fp1, "Accept-Encoding: gzip,deflate\r\n");
fputs($fp1, "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n");
fputs($fp1, "Keep-Alive: 115\r\n");
fputs($fp1, "Connection: keep-alive\r\n");
fputs($fp1, "Content-length: ".strlen($postdata)."\r\n\r\n");
    fputs($fp1, $postdata."\r\n\r\n");

$response = '';
while(!feof($fp1)) $response .= fgets($fp1,2000);
fclose($fp1);
echo $response;
} 

?>

 

Like I said, I've also tried a standard get request which works as well, just takes 2 minutes.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.