gpt4 book ai didi

java - 读取 URL 的完整 HTML 内容并将其保存到文本文件

转载 作者:搜寻专家 更新时间:2023-11-01 03:52:17 24 4
gpt4 key购买 nike

<分区>

要求:

To read HTML from any website say "http://www.twitter.com ".

Print the retrived HTML

Save it to a text file on local machine .

代码:

import java.net.*;

import java.io.*;

public class oddless {
public static void main(String[] args) throws Exception {

URL oracle = new URL("http://www.fetagracollege.org");
BufferedReader in = new BufferedReader(new InputStreamReader(oracle.openStream()));

OutputStream os = new FileOutputStream("/Users/Rohan/new_sourcee.txt");


String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
}
}

上面的代码检索数据,将其打印在控制台上并将其保存到文本文件中,但大多数情况下它只检索一半代码(因为 html 代码中的行空间)。它不会进一步保存代码。

问题:

How can I save the full html code?

Are there any other alternatives?

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com