0

I found a solution here but It is in java format and I want to use it in a jsp file internally. My code is like this but it shows null when loaded in localhost tomcat:

<html>
<head>
  <title>Number of Google Search Results</title>
</head>
<body>
<%@ page import="org.jsoup.Jsoup" %>
<%@ page import="org.jsoup.nodes.Document" %>
<%@ page import="org.jsoup.nodes.Element" %>
<%@ page import="org.jsoup.select.Elements" %>
<% 
String url = "https://www.google.com/search?q=query";
Document document = Jsoup //
                   .connect(url) //
                   .userAgent("Mozilla/5.0 (Windows; U; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)") //
                   .get();
Element divResultStats = document.select("div#result-stats").first();
%>
<% out.print(divResultStats); %>
</body>
</html>
  • 1
    I suggest you get the Jsoup code running in a Java application before you try to use it in JSP. It'll be much easier to unit test and debug that way. – sprinter Mar 09 '20 at 01:33
  • As @Aidin Azari mentioned, try doing it first in some java app. Also, it might be a better practice to execute the Jsoup code on the backend side, and just add a request attribute and just pass the fetched data to the JSP. – ptr92zet Mar 09 '20 at 10:37

0 Answers0