Automating Javascript Web Form Input

Dave Cragg dave.cragg at lacscentre.co.uk
Mon Feb 27 05:05:04 EST 2012


On 27 Feb 2012, at 00:52, Kay C Lan wrote:

> If I manually enter the pdf file I wish to convert, from the resulting web
> page I can see how I can use LC to download the converted text file, what I
> don't know is how to us LC to feed the website my pdf file so I can
> automate the entire process.
> 
> I can see:
> onload="document.theForm.stdin.focus()"
> form name = "theForm"
> method="post"
> enctype="multipart/form-data"
> action="pdf2txt.htm"
> input type="file"
> name="stdin"
> 
> I'm assuming I use the LC 'post' command, but the example in the LC
> Dictionary is rather basic, my knowledge of Javascript nonexistent, so
> apart from using URLEncode to encode the pathname because it contains /, I
> don't know what of the above I need to include in post, and where I
> substitute the actual pathname to the file I wish to convert.

You'll need to use libURLMultipartFormData for this. Try something like this:

on mouseUp
   
   answer file ""  ## select the pdf file
   put it into tFilePath
   if tFilePath is empty then exit mouseUp
   
   put "http://www.fileformat.info/convert/doc/pdf2txt.htm" into tUrl
   
   put empty into tForm
   put "<file>" & tFilePath into tFile
   
   if libURLMultipartFormData(tForm, "stdin", tFile) is not empty then
          answer it ##error
   else
          set the httpHeaders to line 1 of tForm
          post line 2 to -1 of tForm to url tUrl
      	  put it into field 1 -- or whatever
          if the result is not empty then
         answer the result
      end if
          set the httpHeaders to empty
   end if
end mouseUp

I tried it and it seems to work, but it returns an html page from which you need to extract the url which will download the text file.

Cheers
Dave






More information about the use-livecode mailing list