gpt4 book ai didi

java - 如何修复此处的 MalformedURLException?

转载 作者:行者123 更新时间:2023-12-02 10:01:42 24 4
gpt4 key购买 nike

我希望程序打印出每个网址的文本

HtmlPage points = (HtmlPage) webClient.getPage("https://www.hockey-reference.com/leaders/points_career.html");
String pointsPageContent=points.asText();

HtmlPage assists = (HtmlPage) webClient.getPage("https://www.hockey-reference.com/leaders/assists_career.html");
String assistsPageContent=assists.asText();




final HtmlPage page1 = webClient.getPage(pointsPageContent);

final HtmlPage page2 = webClient.getPage(assistsPageContent);




if(input == "Points") {
System.out.println(page1);

}

else if(input == "Assists") {
System.out.println(page2);
}

else {
System.out.println("not a valid entry, please type either 'Points' or 'Assists' to see the stats for the corresponding category");
}

我应该获取每个 URL 的文本,但它却给了我 MalformedURLException。

最佳答案

正如 @JonSkeet 所说,出现此错误是因为您像获取 URL 一样获取页面内容。

    try {
HtmlPage points = (HtmlPage) webClient.getPage("https://www.hockey-reference.com/leaders/points_career.html");
String pointsPageContent = points.asText();

HtmlPage assists = (HtmlPage) webClient.getPage("https://www.hockey-reference.com/leaders/assists_career.html");
String assistsPageContent = assists.asText();

if (input.equals("Points")) {
System.out.println(pointsPageContent);

} else if (input.equals("Assists")) {
System.out.println(assistsPageContent);
} else {
System.out.println("not a valid entry, please type either 'Points' or 'Assists' to see the stats for the corresponding category");
}
} catch (IOException ex) {
ex.printStackTrace(); // Capture and treat errors
}

只需将页面内容与所需的输入进行比较即可。

关于java - 如何修复此处的 MalformedURLException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55574932/

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