문제

I tried to extract an image from other websites with the following code and i had no problems, but them i tried with other website and nothing happend. no image came up.

protected Void doInBackground(Void... params) {

        try {
            // Connect to the web site
            Document document = Jsoup.connect(https://www.indiegogo.com/project/spy-cam-peek-i/embedded).get();
            // Using Elements to get the class data
            Elements img = document.select("div.i-project-card i-embedded img[src]");


            // Locate the src attribute
            String imgSrc = img.attr("src");
            //Download image from URL
            InputStream input = new java.net.URL(imgSrc).openStream();
            // Decode Bitmap
            bitmap = BitmapFactory.decodeStream(input);



        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
}
도움이 되었습니까?

해결책

Finally y managed to grab the image.

The image src was inside a div under the attribute data-src like this

(<)div class="image" data-src="image.jpg><\div>

So I had to call the class of the div to then call its attribute data-src. problem was that I didn't notice there wasn't a (<)img> tag which I was calling. So the final code was

Elements img document.select("div.image");

String imgSrc = img.attr("data-src");

Cheers everyone.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top