java - Jsoup无法打开html页面Status=-1

标签 java android jsoup ioexception

连接到 URL 时出现以下错误,下面是我遇到的 logcat 错误

下面是我连接到 url 的代码。

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

但是当尝试连接到此网址时,它会抛出错误。

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();
        }
    }

请在这方面帮助我。

最佳答案

网址末尾有一个斜杠。

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

关于java - Jsoup无法打开html页面Status=-1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17973788/

相关文章:

基于XSD值的Java SAX策略模式

java - 如何修复 Oreo 的 AOSP 构建错误?

android - 有什么方法可以使用 ContactsContent Provider 发布 Facebook 状态吗?

android - 如何从android中的listview中的socket io检索数据

javascript - 无法使用 Jquery 和 Jsoup 访问动态生成的元素

java - 如何在 Android 中向文本添加 href 链接?

java - JSoup:难以提取单个元素

java - 连接标题 "GetTitle().Concat(GetTitle()));"

java - 显示复制代码的 NetBeans 设计 View

java - 在 android 中本地存储图像的最佳方式是什么?