On Sun, Apr 09, 2006 at 01:42:10PM +0200, jg wrote:
> Hello again,
> 
> 
> Thanks for your answer, but I am not used to LUA...
> I already have a solution in perl but I would like to make it work with
> links which seems to be faster ! Here is my issue :
> 
> When I do 
> elinks -auto-submit 1 a.html
> I will get : 
> "La saisie du numéro est incorrecte" 
> which is what I want (be patient, request is a little bit long).
> 
> 
> --------------- a.html ----------------
>                 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
>                 Transitional//EN">
>                 <html><head><title>Free</title>
>                 <meta http-equiv="Content-Type" content="text/html;
>                 charset=iso-8859-1">
>                 </head>
>                 <body onload="document.forms[0].submit()">
>                 <form action="http://infopresel.free.fr/identify.pl";
>                 method="post" name="jg">
>                 <INPUT TYPE="text" NAME="numero" VALUE="03893717">
>                 <input type="submit" value="Valider">
>                 </form></body></html>
> --------------- a.html ----------------
> 
> BUT, When I add -dump
> elinks -dump -auto-submit 1 a.html, I can't get the result...
> So I tried to create /home/jg/.elinks/hooks.lua
> http://links.sourceforge.net/links-lua/pwhooks.lua
> 
> --------------- /home/jg/.elinks/hooks.lua ----------------
>                 ---------------------------------------------
>                 --  pre_format_html_hook
>                 ---------------------------------------------
>                 
>                 function pre_format_html_hook (url, html)
>                     local ret = nil
>                 
>                 open ELINKS, "|elinks -dump > $html.txt"
                                                 ^^^^^
Sorry, here is a bug, better would be $url.txt or even better replace it with:
open ELINKS, "|elinks -dump >> output.txt"
                                                 
>                 print ELINKS "$html"
>                 close ELINKS

These three lines were in PERL. In PERL there was easy.
It dumps (in normal browsing mode) every visited page to the file
with filename equal to the url with extension .txt.
In second version dumps are apppended to the file 'output.txt'.
It is good for eg. dumping frames.
This works interactively. If you want to make it non-interactive, the easiest
will be to add 'exit' to the pre_format_html_hook.

In PERL that was three lines. I have no LUA installed currently, but that could
be done something like this in LUA:

function pre_format_html_hook (url, html)
        local tmp = tmpname()
        writeto(tmp) write(html) writeto()
        execute("elinks -dump " .. tmp .. " >> output.txt; rm -f " .. tmp)
        if match("our_pattern", url) then
                exit
        end
end

This code probably won't work, but when you read lua docs you'll correct it
without problems.

It should work like this:
- write html to the temporary file
- invoke elinks in dump mode on that file
- remove temporary file
- quit main elinks when there is such need by invoking exit

-- 
Witek
_______________________________________________
elinks-users mailing list
[email protected]
http://linuxfromscratch.org/mailman/listinfo/elinks-users

Reply via email to