Reputation: 724
I am making an application in flutter for mobile devices (Android and iOS) and I would like to write a function in Dart that given a website returns all and only the strings that are visible to a user browsing it from a browser.
To date I have created the following function:
import 'package:get/get.dart';
import 'package:http/http.dart' as http;
import 'package:html/dom.dart';
import 'package:html/dom_parsing.dart';
import 'package:html/parser.dart';
String getVisibleText(url){
final response = await http.get(Uri.parse(url));
String newResponse = response.body;
Document newDocument = parse(newResponse);
String visibleText = parse(newDocument.body!.text).documentElement!.text;
return visibleText;
}
url = 'https://www.google.com'
print(getVisibleText(url))
but i got this result:
(function(){var src='/images/nav_logo229.png';var iesg=false;document.body.onload = function(){window.n && window.n();if (document.images){new Image().src=src;}
if (!iesg){document.f&&document.f.q.focus();document.gbqf&&document.gbqf.q.focus();}
}
})();Ricerca Immagini Maps Play YouTube News Gmail Drive Altro »Cronologia web | Impostazioni | Accedi (function(){var id='tsuid_1';document.getElementById(id).onclick = function(){if (this.form.q.value){this.checked = 1;if (this.form.iflsig)this.form.iflsig.disabled = false;}
else top.location='/doodles/';};})();Ricerca avanzata(function(){var a,b="1";if(document&&document.getElementById)if("undefined"!=typeof XMLHttpRequest)b="2";else if("undefined"!=typeof ActiveXObject){var c,d,e=["MSXML2.XMLHTTP.6.0","MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP","Microsoft.XMLHTTP"];for(c=0;d=e[c++];)try{new ActiveXObject(d),b="2"}catch(h){}}a=b;if("2"==a&&-1==location.search.indexOf("&gbv=2")){var f=google.gbvu,g=document.getElementById("gbv");g&&(g.value=a);f&&window.setTimeout(function(){location.href=f},0)};}).call(this);PubblicitàSoluzioni aziendaliTutto su GoogleGoogle.it© 2023 - Privacy - Termini(function(){window.google.cdo={height:757,width:1440};(function(){var a=window.innerWidth,b=window.innerHeight;if(!a||!b){var c=window.document,d="CSS1Compat"==c.compatMode?c.documentElement:c.body;a=d.clientWidth;b=d.clientHeight}a&&b&&(a!=google.cdo.width||b!=google.cdo.height)&&google.log("","","/client_204?&atyp=i&biw="+a+"&bih="+b+"&ei="+google.kEI);}).call(this);})(); (function(){google.xjs={ck:'xjs.hp.L0TU2uVtv08.L.X.O',cs:'ACT90oHfWkA5os9VqU2IsUnQ4jMZyTAC0w',excm:[]};})(); (function(){var u='/xjs/_/js/k\x3dxjs.hp.en.cORd4QxWMlo.O/am\x3dAADoBABQAGAB/d\x3d1/ed\x3d1/rs\x3dACT90oHeOZNdzEpi891X373wwHHcgmPZNA/m\x3dsb_he,d';var amd=0;
var d=this||self,e=function(a){return a};var g;var l=function(a,b){this.g=b===h?a:""};l.prototype.toString=function(){return this.g+""};var h={};
function m(){var a=u;google.lx=function(){p(a);google.lx=function(){}};google.bx||google.lx()}
function p(a){google.timers&&google.timers.load&&google.tick&&google.tick("load","xjsls");var b=document;var c="SCRIPT";"application/xhtml+xml"===b.contentType&&(c=c.toLowerCase());c=b.createElement(c);a=null===a?"null":void 0===a?"undefined":a;if(void 0===g){b=null;var k=d.trustedTypes;if(k&&k.createPolicy){try{b=k.createPolicy("goog#html",{createHTML:e,createScript:e,createScriptURL:e})}catch(q){d.console&&d.console.error(q.message)}g=b}else g=b}a=(b=g)?b.createScriptURL(a):a;a=new l(a,h);c.src=
a instanceof l&&a.constructor===l?a.g:"type_error:TrustedResourceUrl";var f,n;(f=(a=null==(n=(f=(c.ownerDocument&&c.ownerDocument.defaultView||window).document).querySelector)?void 0:n.call(f,"script[nonce]"))?a.nonce||a.getAttribute("nonce")||"":"")&&c.setAttribute("nonce",f);document.body.appendChild(c);google.psa=!0};google.xjsu=u;setTimeout(function(){0
I would like to remove all javascript and css code from the output, what is the best way to proceed?
Upvotes: 2
Views: 68