我已經經歷了多篇關於解析等的文章。我看到的大多數回覆都是建議人們使用圖書館或其他東西。我現在的問題是創建一個算法,將獲取我想要的確切信息。我的目的是從天氣網站獲取2個關閉學校的狀態。我開始使用Jsoup作爲推薦人,但我需要幫助。Java使用Jsoup從網站讀取信息
網頁:Click here
圖片:Click here
網頁源的例子:click here
我也許可以弄清楚如何獲取文本的特定行的網頁上,因爲我已經知道名字我正在尋找的學校,但2線下來是我所需要的地位。如果每個學校都有一定的地位,但都是封閉式的或兩小時延遲的,那麼這很容易,所以我不能僅僅爲此尋找答案。我想要一些想法或答案,我可以如何apporach這一點。我將這樣做2次,因爲我想要查找2所學校。我已經有了我可以用來查看他們的名字,我只需要這個地位。
這是我想要做的一個例子。 (須藤代碼)
Document doc = connect(to url);
Element schoolName1 = doc.lookForText(htmlLineHere/schoolname);
String status1 = schoolName.getNext().text();//suppose this gets the line right after which should be my status and then cleans off the Html.
這就是我現在所擁有的
public static SchoolClosing lookupDebug() throws IOException {
final ArrayList<String> Status = new ArrayList<String>();
try {
//connects to my wanted website
Document doc = Jsoup.connect("http://www.10tv.com/content/sections/weather/closings.html").get();
//selects/fetches the line of code I want
Element schoolName = doc.html("<td valign="+"top"+">Athens City Schools</td>");
//an array of Strings where I am going to add the text I need when I get it
final ArrayList<String> temp = new ArrayList<String>();
//checking if its fetching the text
System.out.println(schoolName.text());
//add the text to the array
temp.add(schoolName.text());
for (int i = 0; i <= 1; i++) {
final String[] tempStatus = temp.get(i).split(" ");
Status.add(tempStatus[0]);
}
} catch (final IOException e) {
throw new IOException("There was a problem loading School Closing Status");
}
return new SchoolClosing(Status);
}
任何協助將有助於請! – Yuriah
所有在這裏提出問題的人都希望對他們的問題提供某種幫助。無需大聲呼喊。 – eis
我很抱歉,它沒有得到任何關注,我昨天發佈了這個。 – Yuriah