Commit 361e43e2 authored by Vansh V. Tibrewal's avatar Vansh V. Tibrewal
Browse files

Account for special chars edge case in Wikipedia API

parent 3b7650c4
No related merge requests found
Showing with 2 additions and 1 deletion
+2 -1
......@@ -5,6 +5,7 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.stream.Collectors;
import java.util.stream.Stream;
......@@ -15,7 +16,7 @@ public class Wikipedia {
public static String getPageText(String title) {
try {
URLConnection u = new URL(
"https://" + SITE + "/w/api.php?action=parse&page=" + title.replace(" ", "_") + "&prop=wikitext&format=xml"
"https://" + SITE + "/w/api.php?action=parse&page=" + URLEncoder.encode(title.replace(" ", "_"), StandardCharsets.UTF_8) + "&prop=wikitext&format=xml"
).openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(u.getInputStream(), StandardCharsets.UTF_8));
String xmlPage = in.lines().collect(Collectors.joining("\n"));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment