无法使用 jsoup 解析图像 android

Can't parse image with jsoup android

我正在接受解析新闻网站的培训。我在解析图像时遇到了一些问题。

http://www.ua-football.com/ - class="stripe-container

代码来自 MainActivity.class

         @Override
           protected Void doInBackground(Void... params){
        arraylist = new ArrayList<HashMap<String, String>>();
        try{
            Document doc = Jsoup.connect(url).userAgent("\"Mozilla/5.0      (Macintosh; U; Intel Mac OS X; de-de) AppleWebKit/523.10.3 (KHTML, like Gecko) Version/3.0.4 Safari/523.10").get();
            for (Element container : doc.select("div[class=stripe-container]")){
                for (Element ul_li : container.select("ul li")){
                    HashMap<String, String> map = new HashMap<String, String>();


                    Elements img_src = ul_li.select("img[src]");
                        String img = img_src.attr("src");
                        System.out.println(img);
                    //map.put("logo", img);
                    map.put("text", ul_li.text());
                    map.put("logo",img);
                    arraylist.add(map);


                }
            }



        } catch (IOException e){
            e.printStackTrace();
        }
        return null;
    }

getView 来自 Adapter

 @Override
public View getView(int position, View convertView, ViewGroup parent) {
    TextView text_of_news;
    ImageView logo;

    inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View itemView = inflater.inflate(R.layout.list_item, parent, false);
    // Get the position
    resultp = data.get(position);

    text_of_news = (TextView) itemView.findViewById(R.id.text_of_news);
    logo = (ImageView) itemView.findViewById(R.id.imageView);

    text_of_news.setText(resultp.get(MainActivity.TEXT_OF_NEWS));
    imageLoader.DisplayImage(resultp.get(MainActivity.LOGO), logo);



    return itemView;
}

打开应用程序后我可以看到文本,但我从 ImageLoader

中找到默认的 image 而不是所需的图像

我的失败在哪里?

Can't parse image with jsoup android

要获取图像 src,您可能正在寻找类似以下内容的内容:

Document doc = Jsoup.connect("http://www.ua-football.com/").timeout(30000).get();
Elements imgs = doc.getElementsByClass("stripe-container").select("img");
for (Element img : imgs) {      
   String imgSrc = img.attr("src");
   System.out.println(imgSrc);
}

标准输出

http://www.ua-football.com/img/upload/17/21ef0d.jpeg
http://www.ua-football.com/img/upload/17/21d43e.jpeg
http://www.ua-football.com/img/upload/16/2174cb.jpeg
etc...

阅读更多关于 jsoup dom-navigation