【发布时间】:2017-04-24 17:25:51
【问题描述】:
我正在尝试在 java 中编写一个函数,该函数基本上将从 url 的 div 复制和粘贴 html 代码。有问题的数据来自http://cdn.espn.com/sports/scores#completed,但是当使用 io 流复制到我的函数中时,数据是不可见的。当我单击检查和控制-f“完成的足球”时,数据本身是可见的,但我的代码根本没有检索到它。这是我使用的代码。
package project;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
public class DownloadPage {
public static void main(String[] args) throws IOException {
// Make a URL to the web page
URL url = new URL("http://cdn.espn.com/sports/scores#completed-soccer");
// Get the input stream through URL Connection
URLConnection con = url.openConnection();
InputStream is =con.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String line = null;
// read each line and write to System.out
while ((line = br.readLine()) != null) {
System.out.println(line);
}
}
【问题讨论】:
标签: java html parsing web-scraping jsoup