Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to extract information from my college website using python. Here is the link of the website.

http://studzone.psgtech.edu/CommonPage.aspx

I have the exam results page locally saved. I want to know how to submit data using the local file and get the resulting page using python. I've looked into urllib2, requests, mechanize frameworks. But haven't got any useful information on submitting data from a local HTML file. Thanks in advance.

I've use following code to obtain the web page and store it in a object. Is there anyway to post the form in that webpage stored in the page variable? I can edit the field such that value="something".

Python
import urllib2
import requests

page = urllib2.urlopen("http://google.com/").read()
c = requests.post(page, data) #is something like this possible?
Posted

1 solution

Of course. See:
https://docs.python.org/2/howto/urllib2.html[^]
or
https://docs.python.org/2/library/httplib.html[^]

Look for POST related sections...
Still, before you can do this, you might need to investigate http traffic. You might need to mimic more browser action, than just posting. You might need to add session state, log in, and so on. Fiddler[^] is a good tool to start with.
 
Share this answer
 
Comments
Ashwin2013 29-Sep-15 14:13pm    
I used urllib2 and requests in combination to accomplish the task. Thanks anyway.

requests contains library to parse local html and page can be retrieved using urllib2 and requests while requests have more control with setting cookies and sessions. Use it wisely.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900