Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function test() {
- var html = UrlFetchApp.fetch('https://docs.google.com/forms/d/1awKpg_diniayS6360kNXrcgihk36azQ3DJEaZqXDY7A/viewform?embedded=true').getContentText();
- var form = html.match(/<form(.*?)</form>/g);
- Logger.log(form);
- }
- function doGet() {
- // En vez de obtener el html con UrlFetchApp.fetch(), se usa esto a modo de ejemplo
- var html = '<html>'
- + ' <body>'
- + ' <p>Texto a borrar</p>'
- + ' <form>'
- + ' <input type="radio" name="sexo" value="masculino" checked="1"> Masculino<br>'
- + ' <input type="radio" name="sexo" value="femenino"> Femenino'
- + ' </form>'
- + ' <p>Esto no debe aparecer</p>'
- + ' <form>'
- + ' Segundo form <input type="button" value="Funciona">'
- + ' </form>'
- + ' </body>'
- + '</html>';
- // Se crea el documento
- var doc = Xml.parse(html, true); //Xml.parse está obsoleto pero sigue funcionando y mejor que XmlService
- var body = doc.html.body.toXmlString(); //truco para que funcione XmlService (sino no acepta HTML que no cumple como XML)
- var atom = XmlService.getNoNamespace();
- doc = XmlService.parse(body);
- var root = doc.getRootElement();
- var i, resultado = '';
- // Se obtienen todos los forms
- var forms = getElementsByTagName(root, 'form');
- // Se unen en un string
- for(i in forms) resultado += XmlService.getRawFormat().format(forms[i]);
- // Envíar resultado como salida del script
- return HtmlService.createHtmlOutput(resultado);
- }
- function getElementsByTagName(element, tagName) {
- // Fuente: https://sites.google.com/site/scriptsexamples/learn-by-example/parsing-html
- var data = [];
- var descendants = element.getDescendants();
- for(i in descendants) {
- var elt = descendants[i].asElement();
- if( elt !=null && elt.getName()== tagName) data.push(elt);
- }
- return data;
- }
- $('form').each(function(){
- var html = $( this ).html();
- })
- function doGet() {
- var html = UrlFetchApp.fetch('https://docs.google.com/forms/d/1awKpg_diniayS6360kNXrcgihk36azQ3DJEaZqXDY7A/viewform?embedded=true').getContentText();
- var output = html.match(/<form[sS]*form>/g);
- return HtmlService.createHtmlOutput(output);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement