Question

i need a Java program to grab all website content with hyperlinks and all contents using...

i need a Java program to grab all website content with hyperlinks and all contents using array and loop and thank u

0 0
Add a comment Improve this question Transcribed image text
Answer #1

package org.jsoup.examples;
import org.jsoup.Jsoup;
import org.jsoup.helper.Validate;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.IOException;

/**
Example program to list links from a URL.
**/
public class ListLinks {
    public static void main(String[] args) throws IOException {
        Validate.isTrue(args.length == 1, "usage: supply url to fetch");
        String url = args[0];
        print("Fetching %s...", url);

        Document doc = Jsoup.connect(url).get();
        Elements links = doc.select("a[href]");
        Elements media = doc.select("[src]");
        Elements imports = doc.select("link[href]");

        print("\nMedia: (%d)", media.size());
        for (Element src : media) {
            if (src.tagName().equals("img"))
                print(" * %s: <%s> %sx%s (%s)",
                        src.tagName(), src.attr("abs:src"), src.attr("width"), src.attr("height"),
                        trim(src.attr("alt"), 20));
            else
                print(" * %s: <%s>", src.tagName(), src.attr("abs:src"));
        }

        print("\nImports: (%d)", imports.size());
        for (Element link : imports) {
            print(" * %s <%s> (%s)", link.tagName(),link.attr("abs:href"), link.attr("rel"));
        }

        print("\nLinks: (%d)", links.size());
        for (Element link : links) {
            print(" * a: <%s> (%s)", link.attr("abs:href"), trim(link.text(), 35));
        }
    }

    private static void print(String msg, Object... args) {
        System.out.println(String.format(msg, args));
    }

    private static String trim(String s, int width) {
        if (s.length() > width)
            return s.substring(0, width-1) + ".";
        else
            return s;
    }
}

Add a comment
Know the answer?
Add Answer to:
i need a Java program to grab all website content with hyperlinks and all contents using...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • program is called grabing website data, to scrap all data from a website ( for example...

    program is called grabing website data, to scrap all data from a website ( for example google ) with tabs (hyperlinks)and copying them in a file using java their is HTML code but i can't remeber it must be added and we must get these data in an array then we copy it in the file and please simply without using advanced java libraries , is there any help

  • I need to write a program in java using two array lists. I need to program...

    I need to write a program in java using two array lists. I need to program to prompt the user to enter a day of the week and return an output of a predetermined temperature for the day they selected. I also need the program the output the average of daily temperatures across the week if the user inputs "week". So basically if i set the temperatures to something arbitrary i.e.: Monday = 50 Tuesday = 55 Wednesday = 52...

  • I need help with my assignment. It is a java program. Please make it as simple...

    I need help with my assignment. It is a java program. Please make it as simple as you can. Create an ArrayList with elements the objects of previous class. Using a simple loop populate the ArrayList with data from some arrays with data, or from console. Use a loop with iterator and write the information in a File using PrintWriter. Use this address for the file (c:\\result\\MyData.txt). Use the Scanner class to display the content of the file on console.

  • Help in Java please: This is not meant to be a program that compiles and runs....

    Help in Java please: This is not meant to be a program that compiles and runs. I only need program segments. DO NOT submit a complete Java file with documentation and other content. Write the statements (NOT an entire program) to: Ask the user for the number of students in a classroom. Validate the number of students to make sure it’s a positive value. NOTE: positive numbers are numbers greater than 0. Define an array named stud that can hold...

  • I'm trying to construct this program in C#, I found some similiar problems in Java but...

    I'm trying to construct this program in C#, I found some similiar problems in Java but as a beginner, its not very easy to follow along with the Java code. Create a Console application named RelativesApp to help you remember your relatives’ birthdays. ·Create a Relative class that includes auto-implemented properties for the relative's name, their relationship to you, and two integers to represent their birthday –month, day. ·Declare an array of at least 12 relative objects. ·Fill the array...

  • I need to write a Java program. Declare and initialize an ArrayList of type Employee. In...

    I need to write a Java program. Declare and initialize an ArrayList of type Employee. In a while loop, keep initializing objects of type Employee, storing them in the array, and allow the user to enter ID, salary, and leaveDays of the each employee one by one and in one line. Once the user entered a -1, stop initializing new employees, and print "You entered [actual length of array] employees. Thank you!" Create a FOR loop that goes through every...

  • Write a java program that create a 2 dimensional array of type double of size 10...

    Write a java program that create a 2 dimensional array of type double of size 10 by 10. Fill the array with random numbers using a random number generator. Print the array contents. Write a java program that creates a file called data.txt that uses the PrintWriter class. Write the numbers 1 to 42 into the file. Close the file. Attach both files. Thank you in advance

  • Hello, I need the correct answer for this please , a quick sort program -java code-...

    Hello, I need the correct answer for this please , a quick sort program -java code- that have 2 arrays first one will have different values , the second one the values will be from smallest to largest number then the program have a quick sort to do it for both of them and will count the time - how long the quick sort is take for each one - which array is faster. Thank you ❤️

  • Q1. Write a program in Java         a. Create 2 separate arrays, of user defined values,...

    Q1. Write a program in Java         a. Create 2 separate arrays, of user defined values, of same size         b. Add these 2 arrays. ........................................................................................................................... Q2. Write a program in java (using loop) input any10 numbers from user and store in an array. Check whether each of array element is positive, negative, zero, odd or even number. ............................................................................................................................ Q3. Write a program in Java to display first 10 natural numbers. Find the sum of only odd numbers. .............................................................................................................................. Q4....

  • Please merge all the codes below and add comments using JAVA Program. I need a complete...

    Please merge all the codes below and add comments using JAVA Program. I need a complete code which is the combination of the following codes: // Merges the left/right elements into a sorted result. // Precondition: left/right are sorted public static void merge(int[] result, int[] left,                                        int[] right) {     int i1 = 0;   // index into left array     int i2 = 0;   // index into right array     for (int i = 0; i < result.length; i++)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT