简体   繁体   中英

HTML parsing using JSoup

I am new to jsoup. I want to parse html but the problem is with the URL which we have to specify in jsoup.connect(url) , I will get this url in response from some other page at runtime. Is there any way to pass the received url into jsoup.connect ? I had read something like:

String html = response.getContentAsString(); 
Document document = Jsoup.parse(html);

But I am not getting exactly how to use it. I would love to know if some other way of doing this is better than jsoup.

"parse" function accepts html content string, not url.

According to jsoup javadoc , the following should solve your problem:

Document doc = Jsoup.connect("http://example.com").get();

pay attention to the fact that "connect" method returns Connection object, but, in fact, does not connect. Therefore additional call to "get" (or "put", depending on the handler type on the server side).

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