[英]Reading URLs from a HTML webpage and writing them to a file
我想创建一个简单的程序,只读取用户指定网页的源代码中<a>
标记中包含的URL。 由于我是Java新手,因此不胜感激。 这是我到目前为止的内容,但这只会将整个网页添加到文件中...
import javax.swing.*;
import java.net.*;
import java.io.*;
public class siteReader {
public static void main(String[] args) throws Exception {
URL address = new URL(JOptionPane.showInputDialog("Input a webpage address:"));
BufferedReader in = new BufferedReader(new InputStreamReader(address.openStream()));
}
}
Jsoup可以通过以下方式完成您想要的操作:
Document doc = Jsoup.connect(address).get();
Elements links = doc.select("a");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.