1

I want to download an iCal file to my app. It works fine, but the link to this file will change every 6 months. The page/link that inherits the link to the file will not change, so I want to look into the code of the main page and find the link to the iCal file to download it.

I think this may work best with javascript, but I have no clue about that. There is also no tag or id I could search for.

This is the page to search for the link:

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

The search pattern would be "/splan/ical" There I found the link to the file.

In the end I would need "/splan/ical?type=pg&puid=6&pgid=1617&lan=de" stored somewhere.

Right now I just use the Downloadmanager to get the file, no html-code is stored anywhere.

Hope someone can help. Thanks.

EDIT:

Here is the part of the html source that contains the link (first href):

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


<a href="http://www.progotec.de/site/splandok/iCal-Anbindung"
 target="_blank"><img style="align: middle; border: 0;"
 alt="Hilfe zu ICal"
 src="/splan/pictures/hilfe.png"
 title="Hilfe zu ICal" height="20" /></a>
</td>
</tr>
kinglite
  • 339
  • 3
  • 20
  • 1
    You could better post the part of the html source that contains the link. – greenapps Dec 02 '14 at 10:40
  • I think you don't have any JavaScript Framework in your App, thats why it might be better to just download the page and search on that downloaded page with regular expressions instead of using JS on the "online" page. – Eun Dec 02 '14 at 10:55
  • Thanks for your answers @Eun: Do you mean saving the entire html code somewhere and search for the link with regular expressions? Do you have an example or something? – kinglite Dec 02 '14 at 12:14
  • @kinglite Exact thats what I mean. [How do I use the Simple HTTP client in Android?](http://stackoverflow.com/questions/4457492/how-do-i-use-the-simple-http-client-in-android) & [Android regular expression - return matched string](http://stackoverflow.com/questions/9366742/android-regular-expression-return-matched-string) – Eun Dec 02 '14 at 12:34
  • @Eun: Ok, now my head hurts from regex. I can't get it to work. What I try is to use the regex from winner_joiner below. But it will not work. My Pattern is "/splan/ical[^\"]*". (how can I post code in comments?) – kinglite Dec 02 '14 at 13:47
  • for `p.matcher`you must pass the contents of the downloaded html. – Eun Dec 02 '14 at 13:55
  • `Pattern p = Pattern.compile("/splan/ical[^\"]*"); Matcher m = p.matcher("html"); if (m.find()) Toast.makeText(getActivity(), m.group(), Toast.LENGTH_LONG) .show(); else Toast.makeText(getActivity(), "NOOOO", Toast.LENGTH_LONG) .show(); ` – kinglite Dec 02 '14 at 13:58
  • @Eun: Argh, I just saw that i pass "html" instead of the object html . now it works fine. – kinglite Dec 02 '14 at 14:02

1 Answers1

1

i am not sure what you are looking for, but with this javscript-script you can find the link.

//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
  href="/splan/ical?type=pg&amp;puid=8&amp;pgid=2505&amp;lan=de"><img
   style="align: middle; border: 0;" src="/splan/pictures/ical.png"
   alt="ics feed" height="20" /></a> 
  ...
</body>

here a regex demo over the whole stundenplan.hs-furtwangen.de: http://regex101.com/r/wF3wU4/1

winner_joiner
  • 12,173
  • 4
  • 36
  • 61
  • this looks interesting. 1. I would need to save this string somewhere. Could I do this whith String link = document.body.innerHTML.match(/(\/splan\/ical[^"]*)/gi); ? 2. is "document" the object in which I save my html-code? – kinglite Dec 02 '14 at 11:58
  • ad 1. yes you can. ad 2. `document` is the HTML DOM document. if your have the "html-code" in a string/variable, than `link = codeStringVariable.match(/(\/splan\/ical[^"]*)/gi)` should be enough(when using javscript). – winner_joiner Dec 02 '14 at 12:42