连接到我正在获取的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();
}
}
请帮助我。
答案 0 :(得分: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 "-
...
答案 1 :(得分: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();
}