我正在制作一个软件,该软件应该从提供的url中检索网页的标题并尝试使用JSoup来实现该目标。 的联系大多来自YouTube和JSoup完美的作品和他们在一起,但偶尔的输入会以概率密度函数,像这样的形式:http://www.ninsheetmusic.org/download/pdf/2066 这时候,我得到以下异常:从pdf中获取html内容url(jsoup)
org.jsoup.UnsupportedMimeTypeException: Unhandled content type. Must be text/*, application/xml, or application/xhtml+xml. Mimetype=application/pdf, URL=http://www.ninsheetmusic.org/download/pdf/2066
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:689)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:628)
at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:260)
at org.jsoup.helper.HttpConnection.get(HttpConnection.java:249)
at core.Request.parseTitle(Request.java:54)
at core.Request.<init>(Request.java:29)
at core.GrakeBot.parseRequest(GrakeBot.java:161)
at core.GrakeBot.onMessage(GrakeBot.java:59)
at org.jibble.pircbot.PircBot.handleLine(PircBot.java:990)
at org.jibble.pircbot.InputThread.run(InputThread.java:92)
现在我把它JSoup不处理pdf,但有什么我可以在这里做,以避免这种异常,并获得网页标题?
这是我现在使用的代码:
private String parseTitle(String link)
{
Document doc = null;
String title = "Title could not be retrieved";
if (getType() == RequestType.YOUTUBE)
{
try
{
doc = Jsoup.connect(getLink()).get();
title = doc.getElementById("eow-title").text();
} catch (IOException e)
{
e.printStackTrace();
}
return title;
}
else if (getType() == RequestType.SHEET)
{
try
{
doc = Jsoup.connect(getLink()).get();
title = doc.getElementsByTag("title").text();
} catch (IOException e)
{
e.printStackTrace();
}
return title;
}
else
return title;
}
*“它看起来像Apache PDFBox的是你想要的“* - 严格来说,Apache PDFBox只是* OP可用于此任务的众多* PDF库之一... – mkl
我觉得添加Apache PDFBox对于我的目标并不是最佳选择。 我可能会说这里真的很愚蠢,纠正我,如果我错了: 通过在Firefox中打开上述链接并打开页面检查器,我发现有一些HTML代码,实际上有一个
@RamzahBeoulve你可以打开一个普通的套接字连接,然后用JSoup解析。 –