In this project, we took words by parsing HTML on a page on Wikipedia through JSoup in Android Studio. Bu projede Android Studio'da JSOUP ile internetteki bir sayfadan(Wikipedia) HTML'i parçalayarak kelimeleri aldık.
Add These Libraries
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
Add This Dependency
implementation 'org.jsoup:jsoup:1.12.1'
Add This Manifest Line
<uses-permission android:name="android.permission.INTERNET" />
After had got data splitted by 'space'
arrOfWords = strDesc.split(" ", 50);
private class GetWordsFromWebSite extends AsyncTask<Void, Void, Void> {
ProgressDialog progressDialog = new ProgressDialog(MainActivity.this);
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected Void doInBackground(Void... params) {
GetWordsandParse();
return null;
}
//get words on website
private void GetWordsandParse() {
try{
String newURL="https://en.wikipedia.org/wiki/Rosika_Schwimmer";
Document doc = Jsoup.connect(newURL).get();
Elements trs = doc.select("div.mw-parser-output");
for (Element tr : trs) {
String strDesc = tr.text();
arrOfWords = strDesc.split(" ", 50);
}
}catch (Exception e){
e.printStackTrace();
}
}
@Override
protected void onPostExecute(Void aVoid) {
int i=0;
for(String word: arrOfWords)
System.out.println(i++ +".- "+word);
}
}