Ce diaporama a bien été signalé.
Le téléchargement de votre SlideShare est en cours. ×

Write a simple java code for the following question- Access a website.docx

Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité

Consultez-les par la suite

1 sur 2 Publicité

Write a simple java code for the following question- Access a website.docx

Télécharger pour lire hors ligne

Write a simple java code for the following question:
Access a website of your choice with a comparison chart or any table of information.

Input: Name or any string to search for in a row.

Output: Description or another information about the given name in the same row

For example, in this website: http://www.tabletpccomparison.net/

Sample input (name): Microsoft Surface Pro 3

Sample Output(OS): Win 8.1 Pro

OR

Sample input (name): Sony Xperia Z2

Sample Output(OS): Android 4.4
Solution
import java.util.Scanner;
/**
*
* @author prmsh
*/
public class ReadWebsite {
public static void main(String args[]) throws MalformedURLException, IOException {
// stroring URL
String url = \"http://www.tabletpccomparison.net/ \";
Parser parser = new Parser(url);
NodeList movies = parser.extractAllNodesThatMatch(
new AndFilter(new TagNameFilter(\"table\"),
new HasAttributeFilter(\"class\", \"tableJX2 tableJX\")));

Scanner sc = new Scanner(System.in);
System.out.println(\"Enter input(name): \");
String input = sc.nextLine();
String result = movies.find(input);
System.out.println(\"Result: \"+result);
}
}
.

Write a simple java code for the following question:
Access a website of your choice with a comparison chart or any table of information.

Input: Name or any string to search for in a row.

Output: Description or another information about the given name in the same row

For example, in this website: http://www.tabletpccomparison.net/

Sample input (name): Microsoft Surface Pro 3

Sample Output(OS): Win 8.1 Pro

OR

Sample input (name): Sony Xperia Z2

Sample Output(OS): Android 4.4
Solution
import java.util.Scanner;
/**
*
* @author prmsh
*/
public class ReadWebsite {
public static void main(String args[]) throws MalformedURLException, IOException {
// stroring URL
String url = \"http://www.tabletpccomparison.net/ \";
Parser parser = new Parser(url);
NodeList movies = parser.extractAllNodesThatMatch(
new AndFilter(new TagNameFilter(\"table\"),
new HasAttributeFilter(\"class\", \"tableJX2 tableJX\")));

Scanner sc = new Scanner(System.in);
System.out.println(\"Enter input(name): \");
String input = sc.nextLine();
String result = movies.find(input);
System.out.println(\"Result: \"+result);
}
}
.

Publicité
Publicité

Plus De Contenu Connexe

Similaire à Write a simple java code for the following question- Access a website.docx (20)

Plus par lez31palka (20)

Publicité

Plus récents (20)

Write a simple java code for the following question- Access a website.docx

  1. 1. Write a simple java code for the following question: Access a website of your choice with a comparison chart or any table of information. Input: Name or any string to search for in a row. Output: Description or another information about the given name in the same row For example, in this website: http://www.tabletpccomparison.net/ Sample input (name): Microsoft Surface Pro 3 Sample Output(OS): Win 8.1 Pro OR Sample input (name): Sony Xperia Z2 Sample Output(OS): Android 4.4 Solution import java.util.Scanner; /** * * @author prmsh */ public class ReadWebsite { public static void main(String args[]) throws MalformedURLException, IOException { // stroring URL String url = "http://www.tabletpccomparison.net/ "; Parser parser = new Parser(url); NodeList movies = parser.extractAllNodesThatMatch( new AndFilter(new TagNameFilter("table"),
  2. 2. new HasAttributeFilter("class", "tableJX2 tableJX"))); Scanner sc = new Scanner(System.in); System.out.println("Enter input(name): "); String input = sc.nextLine(); String result = movies.find(input); System.out.println("Result: "+result); } }

×