Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

To Tell the Truth Write a java program to query http://www.pravdareport.com, htt

ID: 3714259 • Letter: T

Question

To Tell the Truth

Write a java program to query http://www.pravdareport.com, http://pravda.ru http://www.lefigaro.fr, and http://www.independent.co.uk and display everything between the first occurrence of the tags and Things like are called HTML tags. The ends the tag . If a webpage contains Sophie, Sally and Jack your program should print Sophie, Sally and Jack If no … tags appear, print a message such as “No was found in http://pravda.ru.” Your program should handle any thrown exceptions with an informative message.

Grading Elements: • Submission adheres to your instructor’s rules for submissions and code quality and conventions. • Program opens network connections to each of the designated web sites • Program reads the designated web pages • Program scans the incoming datastream for the appropriate HTML tags • Program extracts the designated information, or prints a message if no such information is found • Program catches any exceptions and prints an informative

Explanation / Answer

Based on the question given its not clear whether you want output between the tags or the entire html tag. Below program returns the entire content including html tags. Please let me know if this is sufficient of your requirement is to find something like below :

<html><open>yes</open></html> --> output yes. Is this what you expecting ?

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Scanner;

public class HtmlTags {
public static void main(String args[]) {
try {
Scanner reader = new Scanner(System.in);
System.out.println("Enter a website name :");
String websiteAddress = reader.nextLine();

if (websiteAddress != null) {
URL url = new URL(websiteAddress);

// Read all the text returned by the server
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String str;
while ((str = in.readLine()) != null) {
str = in.readLine().toString();
if (str != null) {
System.out.println(str);
// str is one line of text; readLine() strips the newline character(s)
} else {
System.out.println("No output returned: Make sure the web address is correct");
}
}
in.close();
} else {
System.out.println("Please do enter a valid website address!!!!!");
}
reader.close();
} catch (MalformedURLException e) {
System.out.println("Not a valid URL provided: Please enter a valid one");

} catch (IOException e) {
e.printStackTrace();
}
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote