簡體   English   中英

無法從某些網址獲取圖像內容

[英]Not able to get image content from some urls

在開發插件以從各個網頁復制圖像的過程中,我正在嘗試從Java代碼中的URL獲取圖像,如下所示:

URL urlString = new URL("http://www.hdwallsource.com/img/2014/7/harley-davidson-wallpaper-16885-17439-hd-wallpapers.jpg");
URLConnection conn = urlString.openConnection();
System.out.println("--------------------getContentType: "+conn.getContentType()+"....conn:"+conn);
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
System.out.println("--------------------"+in);
String inputLine;
while ((inputLine = in.readLine()) != null)
    System.out.println(inputLine);
     in.close();

對於此特定的圖像路徑:“ http://www.hdwallsource.com/img/2014/7/harley-davidson-wallpaper-16885-17439-hd-wallpapers.jpg ”我正在獲取getContentType:text / html; charset = UTF-8。 而我的sysout為我提供了該圖像可用頁面的所有HTML代碼。 對於所有其他圖像路徑,例如: http : //img6a.flixcart.com/image/mobile/n/q/a/motorola-moto-g-400x400-imadsmbwhznhucjj.jpeg我正在獲取正確的圖像/ jpeg類型和圖像內容。 任何幫助將不勝感激。

如果您在瀏覽器的新隱身窗口中打開第一個鏈接,則會發現您也獲得了html頁面。 該網站可能有一些不向抓取工具顯示圖片的政策。 看來,如果您沒有該站點的Cookie,它們將顯示html頁面。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM