Faced such a question: with the help of JSOUP, I prepared the main page of the site. All links are listed in ArrayList<String> . Next, I want to parse these links, but I can’t initialize them. Code for homepage:

 protected String doInBackground(String... arg) { try { Document doc = Jsoup.connect("http://site.com/archive/").get(); link = doc.select("a[href]"); for (Element links : link) { LinkList.add(links.attr("abs:href")); } } catch (IOException e) { e.printStackTrace(); } return null; } 

For the subsidiary:

 protected Void doInBackground(Void... params) { try { //for (int i = 0; i < LinkList.size(); i++) { //url = url.toLowerCase(); //if( !LinkList.contains(url) ){ Document doc1 = Jsoup.connect(url[0]).get(); Elements img = doc1.select("#strip"); String imgSrc = img.attr("src"); InputStream input = new java.net.URL(imgSrc).openStream(); bitmap = BitmapFactory.decodeStream(input); //} } catch (IOException e) { e.printStackTrace(); } return null; } 

I tried to bring ArrayList to a simple array, but to no avail:

 public ArrayList<String> LinkList = new ArrayList<String>(); String[] url = LinkList.toArray(new String[LinkList.size()]); 

The idea is simple: take turns on the links from the dynamic array and check for tags, that’s just not working. I would be grateful for any tips.

Work code:

 Document doc = Jsoup.connect(url).get(); Elements links = doc.select("a[href]"); String link_addr = links.get(3).attr("abs:href"); Document link_doc = Jsoup.connect(link_addr).get(); Elements img = link_doc.select("#strip"); String imgSrc = img.attr("src"); InputStream input = new java.net.URL(imgSrc).openStream(); bitmap = BitmapFactory.decodeStream(input); 
  • Hello, I did this only I used several lists, here is my git - Konstantin Petrenko

1 answer 1

Checked that you are in LinkList after parsing? Maybe you need to change

 LinkList.add(links.attr("abs:href")); 

on

 LinkList.add(links.attr("href")); 
  • With such a replacement, it displays not site.com/link1 and / link1 / linkList.get(0) successfully shows the 1st link - d521473