-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHtmlFetcher.java
More file actions
35 lines (33 loc) · 1.13 KB
/
HtmlFetcher.java
File metadata and controls
35 lines (33 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
/**
* The HtmlFetcher class is responsible for fetching HTML content from a given URL.
* It reads the HTML content line by line and returns it as a list of strings.
*/
public class HtmlFetcher {
/**
* Fetches HTML content from the specified URL.
*
* @param urlString the URL to fetch HTML content from
* @return a list of strings, each representing a line of HTML content
*/
public List<String> fetchHtmlLines(String urlString) {
List<String> lines = new ArrayList<>();
try {
URL url = new URL(urlString);
try (BufferedReader reader = new BufferedReader(
new InputStreamReader(url.openStream(), "UTF-8"))) {
String line;
while ((line = reader.readLine()) != null) {
lines.add(line);
}
}
} catch (Exception e) {
System.out.println("Url connection error while fetching html lines");
}
return lines;
}
}