html - post text from files into a web page form using python -
I have a set of text files I need to input them on one web server after each other. I know That's how to input text using mechanized, but not know how to extract text from files stored on computer and input one after another. In other words, say there are 10 files on my hard disk, I need to post text from a file, submit, then post another file and the process should be run until all the files are posted. Help me with suggestions Thank you.
First create a loop to repeat through your files. Then read the files and encode them into a POST request with urlib and urllib2. You must change the URL, filename pattern and form fields accordingly. Import
url = "http://www.example.com/form" glob import urlib import urllib2 file name in glob for glob ("file * .txt"): filedata = Open (file name) .read () data = urllib.urlencode ({'data': filedata}) urllib2.urlopen (url = url, data = data)
Comments
Post a Comment