我想从这个网站获得标题:http: //feeds.foxnews.com/foxnews/latest
像这个例子:
<title><![CDATA[SUCCESSFUL INTERCEPT Pentagon confirms it shot down ICBM-type target]]></title>
它将显示如下文本:
“成功拦截五角大楼确认击落洲际弹道导弹型目标美国成功进行导弹拦截试验,五角大楼说”
这是我的代码。我用过 jaunt 库。
我不知道为什么它只显示文字“foxnew.com”
import com.jaunt.JauntException;
import com.jaunt.UserAgent;
public class p8_1
{
public static void main(String[] args)
{
try
{
UserAgent userAgent = new UserAgent();
userAgent.visit("http://feeds.foxnews.com/foxnews/latest");
String title = userAgent.doc.findFirst
("<title><![CDATA[SUCCESSFUL INTERCEPT Pentagon confirms it shot down ICBM-type target]]></title>").getText();
System.out.println("\n " + title);
} catch (JauntException e)
{
System.err.println(e);
}
}
}