dimanche 25 septembre 2016

How to Webscrape data from a classic asp website using python. I am having trouble getting the result after submitting the POST form

I am beginner in Web scraping and I have become very much interested in the process. I set for myself a Project that can keep me motivated till I completed the project.

My Project: My Aim is to write a Python Program that goes to my university results page(which happens to be a " xx.asp") and enters my 1. MY EXAM NO 2. MY COURSE 3. SEMESTER and submit it to the website. Clicking on the submit button leads to another " yy.asp" page in which my results are displayed. But I am having a lot of trouble doing the same.

Some Sample Data to try it out:

The Results Website : http://ift.tt/11dQSJK

Register Number : 15te1218

Degree : BTHEE

Exam : Second

Could anyone give me directions of how I am to accomplish the task.

I have written a sample program that I am not really proud of or nor does it work as I wanted.The following is the code that I wrote. I am a biggner so sorry If I did somethings terrible wrong. Please Correct me and would be awesome if you could guide me to solve the problem.

The Website is a .asp website not .aspx. I have provided sample data so that you can see whats happening where we submit a request to the website.

The Code:

import requests

with requests.Session() as c:
    url='http://ift.tt/11dQSJK'
    url2='http://ift.tt/2dhDliv'
    TXTREGNO='15te1218'
    CMBDEGREE='BTHEE~\BTHEE\result.mdb'
    CMBEXAMNO='B'
    DPATH='\BTHEE\result.mdb'
    DNAME='BTHEE'
    TXTEXAMNO='B'
    c.get(url)

payload = {

    'txtregno':TXTREGNO,
    'cmbdegree':CMBDEGREE,
    'cmbexamno':CMBEXAMNO,
    'dpath':DPATH,
    'dname':DNAME,
    'txtexamno':TXTEXAMNO
}
post_request = requests.post(url, data=payload)
page=c.get(url2)

I have no idea what to do next so that i can retrieve my result page(displayed in "url2" -from the code). All the data is entered in link "url" in the program(the starting link were all the info is entered) from where after submitting takes is to "url2" the results page. Please help me make this program.

I took all the post form parameters from Chrome's Network Tab.

Thanks.




Aucun commentaire:

Enregistrer un commentaire