Reputation: 11
When I'm trying to get the site title stackoverflow all goes well, but when I try to get the title beastinvest.su nothing happens. What is the reason?
public class MainActivity extends Activity {
/** Called when the activity is first created. */
Button butTest;
TextView textView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
butTest = (Button)findViewById(R.id.button);
textView = (TextView)findViewById(R.id.textView);
new MyParser().execute("http://beastinvest.su/");
}
public class MyParser extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... links) {
Document doc = null;
String title = null;
try {
doc = Jsoup.connect(links[0]).get();
title = doc.title();
textView.setText(title);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
}
Sorry for my bad English
the problem is that the site AntiDDOS - query returns "To visit this site requires cookies and javacript your browser."
Upvotes: 0
Views: 83
Reputation: 276
Provided site (beastinvest.su) has title in Russian and contains <meta charset="windows-1251"
. I suppose that Jsoup uses UTF-8 encoding by default during parsing routine.
Upvotes: 1
Reputation: 32
Hi use below code,
public class MainActivity extends Activity {
/** Called when the activity is first created. */
Button butTest;
TextView textView;
String title;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
butTest = (Button)findViewById(R.id.button);
textView = (TextView)findViewById(R.id.textView);
new MyParser().execute("http://beastinvest.su/");
}
public class MyParser extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... links) {
Document doc = null;
try {
doc = Jsoup.connect(links[0]).get();
title = doc.title();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
}
public void onPostExecute(String result) {
textView.setText(title);
}
Upvotes: 0