1

我在 HtmlUnit 无头浏览器中打开了一个网页。现在该网页包含一个图像 html 标记,如下所示:

<img src="..." />

所以我只想要那个图像。但问题是图像的相同 src URL 显示差异。每次的图像。意思是,如果我们刷新 img src URL,那么它会显示 diff。每次的图像。

那么如何获取显示在html页面上的图像。


显然(我同时​​找到了答案),列表索引中的美元符号表示列表的最后一个元素。

-->a = list()
 a  =
     ()
-->a(5) = 100
 a  =
// ...
-->a($)
 ans  =
    100.  
4

2 回答 2

1

当您获取HTMLPage时,您必须通过其方法之一获取图像。然后,您可以获得一个HtmlImage,可以将其保存为文件。您只需稍后分析此文件。

于 2010-01-26T11:17:33.403 回答
0

这是使用完全合格的 I 存储图像的功能

   protected String saveImage(String imageUrl) throws Exception {

   InputStream inputStream;
   OutputStream os;
   ByteArrayOutputStream byteArrayOutputStream;
   String destinationFile = "File path where you want ot store the image";
   URL url = new URL(imageUrl);
   inputStream = url.openStream();
   byteArrayOutputStream = new ByteArrayOutputStream();
   os = new FileOutputStream(destinationFile);
   int read;
   String barcode = null;
   while ((read = inputStream.read()) != -1) {
       os.write(read);
       byteArrayOutputStream.write(read);
       barcode = byteArrayOutputStream.toString();
   }
   inputStream.close();
   os.close();
   byteArrayOutputStream.close();



   return barcode;

}

于 2012-03-22T11:25:54.987 回答