0

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."

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

6 Comments

I found another site with the coding windows-1251 (winrus.com/cpage_r.htm) and I get title from the application, I think the problem is not encoded
But its title is in English. Maybe the problem is in the combination of Russian title and windows-1251 encoding.
From the site you provided: If you or your future readers work under a non-Russian Windows, it's not a good idea to use Cyrillic letters in the Title of your page.
I created a simple page with the encoding windows-1251 and Russian title and it works besplprognoz.ru/test.html
Continuing aforementioned quote: Cyrillic title is unavailable in most cases. Not all, but most. Apparently your stub page doesn't prove that encoding isn't the cause of misbehavior. If you provide more examples I'll reconsider my opinion.
|
0
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);
   }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.