lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> Le 8 janv. 2014 à 12:18, Rv Rv <rvrv7575@yahoo.com> a écrit :
> I am beginning to use lua especially with nginx. I need to rewrite the URLs
> *within* the html page.The lua html parser at
> https://github.com/wscherphof/lua-htmlparser provides the URL but as far as
> I understand from its documentation, it will not rewrite the URL. I can
> perhaps reconstruct the page but was wondering if there is already a tool
> that would do that

The lua-gumbo library[1] I'm working on at the moment can mostly
handle this. It started out as a binding for the Gumbo HTML5
parser[2], but it's since grown support for serializing to various
formats too. The parse tree can be mutated, so you could just modify
the links in place and then re-serialize the document it to HTML.
There's also a usage example showing how to find all the links in a
document[3].

(The HTML serializer needs some attention, but it should produce
correct (although ugly) output.)

[1]:https://github.com/craigbarnes/lua-gumbo
[2]:https://github.com/google/gumbo-parser
[3]:https://github.com/craigbarnes/lua-gumbo/tree/master/examples