1

I have a question:

I have a link: http://wap.nastabuss.se/its4wap/QueryForm.aspx?hpl=Teleborg+C+(V%C3%A4xj%C3%B6) and I wanna take only some specific data from this link and to show in textview in Android.

Is this possible in Android, I mean is there any chance by parsing or I don't know, you can suggest me guys.

For example I just want to take this column Nästa tur (min) from that site.

Regards

Eddy Freddy
  • 1,820
  • 1
  • 13
  • 18
Lulzim Fazlija
  • 865
  • 2
  • 16
  • 37
  • Duplicate: http://stackoverflow.com/q/7114282/21727 – mbeckish Oct 22 '11 at 23:35
  • Welcome to stackoverflow! If you find an answer helpful, you can vote it up! If you feel that someone has adequately answered your question, click the check-mark next to the answer to accept it. – Kurtis Nusbaum Oct 22 '11 at 23:40

2 Answers2

2

JSoup is pretty nice and getting popular. Here's how you could just parse the whole table:

URL url = new URL("http://www.nseindia.com/content/equities/niftysparks.htm");
Document doc = Jsoup.parse(url, 3000);

Element table = doc.select("table[title=Avgångar:]").first();

Iterator<Element> it = table.select("td").iterator();

//we know the third td element is where we wanna start so we call .next twice
it.next();
it.next();
while(it.hasNext()){
  // do what ever you want with the td element here

  //iterate three times to get to the next td you want. checking after the first
  // one to make sure
  // we're not at the end of the table.
  it.next();
  if(!it.hasNext()){ 
    break;
  }
  it.next();
  it.next();
}
Kurtis Nusbaum
  • 30,445
  • 13
  • 78
  • 102
  • it says to create a new class JSoup, i checked the official website of JSoup and the file is.jar should i import it in my project as jar or how i can handle this? – Lulzim Fazlija Oct 22 '11 at 23:30
  • Yes, you'll need to add the JSoup jar into you project. – Kurtis Nusbaum Oct 22 '11 at 23:35
  • I added the file JSoup.jar in my project in folder src and still it is saying Create a class JSoup, should i need to paste it somewhere else or what the problem??? i have got lots of errror :S – Lulzim Fazlija Oct 22 '11 at 23:40
  • Here's how to import externals jars into an android project: http://stackoverflow.com/questions/1334802/how-can-i-use-external-jars-in-an-android-project/6859020#6859020 – Kurtis Nusbaum Oct 22 '11 at 23:41
  • i fixed out the importing stuffs, now there is problem in code i guess. – Lulzim Fazlija Oct 23 '11 at 00:13
  • Beware, I didn't fully check this code. It may not work completely, but it should give you a good idea of where to start. The gist is correct, a few modification may be needed to get it fully working though. – Kurtis Nusbaum Oct 23 '11 at 00:16
  • at this line: Element table = doc.select("table[title=Avgångar:]").first(); is stucking??? so how can i solve this, i mean can u please explain me a bit what should i check in more detail?? – Lulzim Fazlija Oct 23 '11 at 00:22
  • is it bc this JSoup maybe doesnt support the letters like å in case of title Avgångar. – Lulzim Fazlija Oct 23 '11 at 00:25
  • I'm not sure, you should ask another JSoup specific question if you're still having issues. – Kurtis Nusbaum Oct 23 '11 at 01:47
-1

If the parsing seems simple enough and you want you could also use regular expressions to find the correct part of the html. Regular expressions will be useful to know at some point anyway. Using some XML/HTML parsing library is the more flexible way to do it (XMLReader for example).

Lycha
  • 9,937
  • 3
  • 38
  • 43
  • do u know any specific example about this case??? Seems like difficult to start from zero. I would appreciate it. – Lulzim Fazlija Oct 22 '11 at 22:55
  • Not recommended - http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 – mbeckish Oct 22 '11 at 23:25