Automatically provide response to HTML form server-side using PHP

145 views Asked by At

I am building an app that extracts data from a website and displays them in my app. I am using PHPQuery to extract data in my server-side code.

However, one page contains an .asp form with two dropdown menus. I need to select an option in both of them and then parse the resulting html. I need to do this server-side, so javascript doesn't seem to be the option.

How can I do so? Can it be done using PHPQuery or some other technology is required?

The page in question is: http://www.bput.ac.in/exam_schedule_ALL.asp

2

There are 2 answers

3
MyStream On BEST ANSWER

Since you're using PHP and phpQuery, I suggest you also try cURL.

Explore what the form submits via JavaScript and replicate that via cURL. Do this to get the format of the posted (assumption) data, which you can then replicate in a cURL request to the same endpoints. JavaScript won't be necessary, and you can get the same results you need. In this case, you won't need the item mentioned next.

Alternatively, if you have a browser, such as webkit, phantomJS, etc, you can write an automation script to run those steps and return the results, depending on exactly what you need returned. See more complete examples here: https://stackoverflow.com/a/17449757/573688 for how others suggest you do this. NOTE this is not usually necessary if you just need to emulate POST requests.

This is a non-coded answer because it's not entirely clear what direction helps you the most.

3
Alexey Rytikov On
  1. On page works JavaScript, which should make an AJAX request to the server and pass the selected value from both SELECT.
  2. The server receives the AJAX request, performs the request to the correct address (you can use phpQuery) and prints the response (gets to the response on AJAX request).
  3. JavaScript on the page receives a response to an AJAX request and performs actions affected.