Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import java.util.ArrayList;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
public class myscrapy {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
//fetching web page via HTTP
Document page = Jsoup.connect("").get();
//selecting all hyperlinks
Elements pageElements ="a[href]");
ArrayList<String> hyperLinks = new ArrayList<String>();
//iterating and extracting
for (Element e:pageElements) {
hyperLinks.add("Text: " + e.text());
hyperLinks.add("Link: " + e.attr("href"));
for (String s : hyperLinks) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment