1
我想從這個網站標題:http://feeds.foxnews.com/foxnews/latest如何使用Jaunt庫從網站上抓取數據?
這樣的例子:
<title><![CDATA[SUCCESSFUL INTERCEPT Pentagon confirms it shot down ICBM-type target]]></title>
,它會顯示文字是這樣的:
「成功攔截五角大樓證實其擊落ICBM-類型目標 美國進行成功的導彈攔截試驗,五角大樓說「
這是我的代碼。我用過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);
}
}
}
你可以嘗試字符串title = userAgent.doc.findFirst( 「
我試過了。輸出是相同的顯示文字只有「foxnew.com」 謝謝你:) – Puppet325