2014-12-02 71 views
1

我想download an iCal file to my app.它工作正常,但鏈接到此文件將change every 6 months.繼承鏈接到文件的頁面/鏈接不會更改,所以我想看看代碼main page and find the link to the iCal file to download it.Android:從HTML代碼中獲取鏈接(無標記/ ID)

我認爲這可能與JavaScript的效果最好,但我不知道這一點。也沒有標籤或ID我可以搜索。

這是網頁搜索的鏈接:

https://stundenplan.hs-furtwangen.de/splan/std?act=tt&lan=de&pu=-1&sel=pg&og=1433&pg=CNB4

的搜索模式將"/splan/ical"還有我發現鏈接到文件。

最後我需要"/splan/ical?type=pg&puid=6&pgid=1617&lan=de"存儲在某個地方。

現在我只使用Downloadmanager來獲取文件,沒有html代碼存儲在任何地方。

希望有人能幫忙。謝謝。

編輯:

這裏是包含鏈接(第一HREF)HTML源代碼的一部分:

<tr> 
 
\t <td /> 
 
\t <td colspan="1"><a 
 
\t \t href="/splan/ical?type=pg&amp;puid=8&amp;pgid=2505&amp;lan=de"><img 
 
\t \t \t style="align: middle; border: 0;" src="/splan/pictures/ical.png" 
 
\t \t \t alt="ics feed" height="20" /></a> 
 

 

 
<a href="http://www.progotec.de/site/splandok/iCal-Anbindung" 
 
\t target="_blank"><img style="align: middle; border: 0;" 
 
\t alt="Hilfe zu ICal" 
 
\t src="/splan/pictures/hilfe.png" 
 
\t title="Hilfe zu ICal" height="20" /></a> 
 
</td> 
 
</tr>

+1

您可以更好地張貼包含鏈接的HTML源代碼的一部分。 – greenapps 2014-12-02 10:40:00

+0

我認爲你的應用中沒有任何JavaScript框架,這就是爲什麼只用正則表達式下載頁面並在下載的頁面上搜索,而不是在「在線」頁面上使用JS會更好。 – Eun 2014-12-02 10:55:59

+0

感謝您的回答 @Eun:您的意思是將整個html代碼保存在某個地方,並搜索正則表達式的鏈接?你有一個例子或什麼? – kinglite 2014-12-02 12:14:12

回答

1

我不知道你在找什麼,但是通過這個javscript腳本你可以找到鏈接。

//like this you could look for the link on the page 
 
//search done with Regularexpression 
 
alert(document.body.innerHTML.match(/(\/splan\/ical[^"]*)/gi));
<body> 
 
<!-- THIS WOULD HAVE TO BE THE BODY OF THE PAGE --> 
 
    ... 
 
    <a 
 
\t \t href="/splan/ical?type=pg&amp;puid=8&amp;pgid=2505&amp;lan=de"><img 
 
\t \t \t style="align: middle; border: 0;" src="/splan/pictures/ical.png" 
 
\t \t \t alt="ics feed" height="20" /></a> 
 
    ... 
 
</body>

這裏正則表達式演示了整個stundenplan.hs-furtwangen.dehttp://regex101.com/r/wF3wU4/1

+0

這看起來很有趣。 1.我需要將此字符串保存在某處。我是否可以這樣做 String link = document.body.innerHTML.match(/(\/splan \/ical [^「] *)/ gi);? 2.是」document「是我保存我的對象html-code? – kinglite 2014-12-02 11:58:16

+0

ad 1. yes you can。ad 2.' document' is the HTML DOM document。如果你的字符串/變量中有「html-code」,那麼你的鏈接就是'link = codeStringVariable.match(/(\/splan \/ical [^「] *)/ gi)'應該足夠了(使用javscript時)。 – 2014-12-02 12:42:55