Trying to practice and get info from website using Jsoup not the website API. My code does not have an error but the text field is not changing. It just shows me a blank space. How would i get info from the website? i'm trying to obtain the Main News so i could post on my website.
My Code:
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.os.AsyncTask;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import java.io.IOException;
import java.io.InputStream;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
Document document;
TextView text;
String ankosh;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
text = (TextView)findViewById(R.id.textView);
new Ankosh().execute();
}
public class Ankosh extends AsyncTask<Void, Void, Void> {
private Exception exception;
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected Void doInBackground(Void... params) {
try {
// Connect to the web site
document = Jsoup.connect("http://www.theguardian.com/us").get();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void feed) {
String ankosh = document.attr("href");
text.setText(ankosh);
}
}
}