[英]Reading URLs from a HTML webpage and writing them to a file
I want to create a simple program that only reads the URLs contained within <a>
tags in the source code of a webpage specified by the user. 我想创建一个简单的程序,只读取用户指定网页的源代码中<a>
标记中包含的URL。 As I am new to Java, any help would be greatly appreciated. 由于我是Java新手,因此不胜感激。 Here is what I have so far, but this only adds the entire webpage to the file... 这是我到目前为止的内容,但这只会将整个网页添加到文件中...
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()));
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.