Why is Jsoup scraping data in Java/Android differently?

Finally! I found a better Solution; to use for loop and add each element separately.

Up vote 0 down vote favorite 1 share g+ share fb share tw.

I have been trying to scrape the 'School Notices' from this URL isleworthsyon.hounslow.sch.uk/ I tried scraping the text in Java and then replaced all " " (which I am not sure what character it is,) with a new line using String. ReplaceAll method and it worked absolutely fine with perfect results, but when I apply the same code to Android..it gives me different results. IN JAVA: String URL = "http://www.isleworthsyon.hounslow.sch.

Uk/"; Document site = null; try { site = Jsoup. Connect(URL).get(); } catch (IOException e) { e.printStackTrace(); } String HTML = site.html(); site. Select("a").remove(); Elements news = site.

Select("div#np_91983-1"); String output = news.text(); String for_output_text = output. ReplaceAll(" ","\n\n"); System.out. Println(for_output_text); } } IN ANDROID: super.

OnCreate(savedInstanceState); setContentView(R.layout. Main); final TextView text = (TextView)findViewById(R.id. Text); String URL = "http://www.isleworthsyon.hounslow.sch.

Uk/"; Document site = null; try { site = Jsoup. Connect(URL).get(); } catch (IOException e) { e.printStackTrace(); } site. Select("a").remove(); Elements news = site.

Select("div#np_91983-1"); String output = news.text(); String for_output_text = output. ReplaceAll(" ","\n\n"); text. SetText(for_output_text); } The two output texts are different as you can see below

btw this is my first go at web scraping Edit: After experiments, The strings I get from news.text() have different spacings in java and android.

Any suggestions as to why that is the case and are there any alternatives? Java android jsoup link|improve this question edited Feb 10 at 10:30 asked Feb 9 at 21:47bakshi_s13.

1 As a point of interest, it's still "in Java" when running on Android. But you haven't described what's different, only shown two essentially identical chunks of code. – Dave Newton Feb 9 at 21:51 Sorry, I know both are in Java, but I couldn't come up with a term quickly enough that would differentiate them.

Btw, I have upadted the question. – bakshi_s Feb 9 at 22:13 please debug your code and compare the strings using diff instead of just looking at the TextView – marcosbeirigo Feb 9 at 22:16 2 Can you print out output.length() and for_output_text.length() as this will give us a big clue as to if the Java/Android Strings are the same. If they are the same length, then my money is on the TextView simply formatting the text differently to your System.out.println().

– Paul Grime Feb 9 at 22:16 Looks the same to me; I'd be somewhat surprised if it was anything substantial beyond output differences. You need to do an actual structural comparison. – Dave Newton Feb 9 at 22:23.

Finally! I found a better Solution; to use for loop and add each element separately. Final TextView text = (TextView)findViewById(R.id.

Text); String URL = "http://www.isleworthsyon.hounslow.sch. Uk/"; Document site = null; try { site = Jsoup. Connect(URL).get(); } catch (IOException e) { e.printStackTrace(); } site.

Select("a").remove(); Elements news = site. Select("div#np_91983-1"); Elements newsline = news. Select("align~=center"); String output = ""; String oldline = ""; for (int I = 0; I Get(i).text(); oldline = newline; output = newline; } text.

SetText(output); Thanks to everyone who helped.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions