简体   繁体   中英

How to fix Jsoup query returning null

I'm trying to retrieve a value of an element with the id loggedin from a WebView using Jsoup, i'm pretty sure it exists in the webpage i'm loading but i keep getting null

this is the code:

Document doc = Jsoup.parse(webView.getUrl());
System.out.println("Webview url= "+webView.getUrl());
Elements loggedin = doc.select("#loggedin");
System.out.println("loggedin= "+ loggedin.first());

System.out output:

04-03 18:48:15.511 17236-17236/com.gci.gestioncapteursincendie I/System.out: Webview url= http://gestioncapteursincendie.herokuapp.com/
04-03 18:48:15.521 17236-17236/com.gci.gestioncapteursincendie I/System.out: loggedin= null

The problem is that you use Jsoup.parse instead of Jsoup.connect

parse used for parsing html page, and connect to load page from specific url

Just replace #loggedin with input#loggedin

Example doc.select("input#loggedin");

Or you can use getElementById to get Element

doc.getElementById("loggedin");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM