1

连接到我得到的 URL 下面是我得到的 logcat 错误

在此之下,我的代码连接到 url。

当我尝试连接到基本网址http://www.apkmania.co/时,它连接成功

但是当尝试连接到这个 url 时,它会抛出一个错误。

07-31 20:47:20.150: I/System.out(14295): IOException: org.jsoup.HttpStatusException: HTTP error fetching URL. Status=404, URL=http://www.apkmania.co/2013/07/blood-sword-thd-v16-apk.html/

休息;

Thread thread=new Thread(new Runnable(){
            public void run(){
                PrepareItem(webrss);
                runOnUiThread(new Runnable(){
                    public void run() {
                        if(dialog.isShowing()){ 
                            try {
                                setDataToHandels();
                            } catch (NullPointerException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                                System.out.println("SET DATA TO HANDELS: " + e);
                            }
                            dialog.dismiss();
                        }
                    }
                });
            }
        });
        thread.start(); 

休息;

private void PrepareItem(String url) {
        System.out.println(url);
        Document content= null;
        try {
            content = Jsoup.connect(url).userAgent("Mozilla").timeout(10*1000).get();
        } catch (final IOException e) {
            // TODO Auto-generated catch block
            System.out.println("IOException: " + e.toString()); 
        }

        int i=0;
        try {

            Elements html1 = content.getElementById("main-wrapper").getElementsByTag("div").get(16).children();
            html1.select("img").first().remove();
            String[] main_content= new String[html1.size()];
            i=0;
            for (Element element_src : html1.select("div")) {
                if (element_src.attr("dir").equals("ltr")) {
                    main_content[i] = element_src.toString();   
                    i++;
                }               
            }

            for (int j = 0; j < main_content.length-2; j++) {
                all_text = all_text+main_content[j];
            }

            all_images_ems = html1.select("img");
            all_images_src = new String[all_images_ems.size()];
            i=0;
            for (Element img_src : all_images_ems) {
                all_images_src[i] = img_src.attr("src");
                i++;
            }

            anchor_link_ems = html1.select("a");
            all_links = new String[anchor_link_ems.size()];
            i=0;
            for (Element anchor_links : anchor_link_ems) {
                all_links[i] = anchor_links.attr("href");
                i++;
            }

        } catch (NullPointerException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

请在这方面帮助我。

4

2 回答 2

0

网址末尾有一个斜杠。

http://www.apkmania.co/2013/07/blood-sword-thd-v16-apk.html/

如果最后删除斜线,它应该可以工作。

http://www.apkmania.co/2013/07/blood-sword-thd-v16-apk.html

编辑:它像这样对我有用。

String url = "http://www.apkmania.co/2013/07/blood-sword-thd-v16-apk.html";
Document content = null;
try {
    content = Jsoup.connect(url).userAgent("Mozilla").timeout(10*1000).get();
} catch (final IOException e) {
    // TODO Auto-generated catch block
    System.out.println("IOException: " + e.toString()); 
}
System.out.println(content);

而且我越来越 <!DOCTYPE html PUBLIC "- ...

于 2013-07-31T15:37:32.883 回答
0

如果将来有人需要,我在这里解决了问题是代码

String url = "http://www.apkmania.co/2013/07/blood-sword-thd-v16-apk.html"    
URL url1;
            InputStream in = null;
            try {
                url1 = new URL(url);
                URLConnection urlConnection = url1.openConnection();
                in = new BufferedInputStream(urlConnection.getInputStream());
            } catch (MalformedURLException e2) {
                // TODO Auto-generated catch block
                e2.printStackTrace();
            }

            Document content= null;
            try {
                content = Jsoup.parse(in, "UTF-8", url);
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                System.out.println(e1.getMessage());
                e1.printStackTrace();
            }
于 2013-08-01T04:24:02.430 回答