Java Reference
In-Depth Information
* @throws IOException Thrown if any error occurs.
*/
public void process(URL url, File saveTo) throws IOException
{
InputStream is = url.openStream();
ParseHTML parse = new ParseHTML(is);
int ch;
while ((ch = parse.read()) != -1)
{
if (ch == 0)
{
HTMLTag tag = parse.getTag();
if (tag.getName().equalsIgnoreCase("img"))
{
String src = tag.getAttributeValue("src");
URL u = new URL(url, src);
String filename = extractFile(u);
File saveFile = new File(saveTo, filename);
this.downloadBinaryPage(u, saveFile);
}
}
}
}
/**
* The main method, create a new instance of the object and call
* process.
* @param args Not used.
*/
public static void main(String args[])
{
try
{
URL u = new URL("http://www.httprecipes.com/1/6/image.php");
ExtractImages parse = new ExtractImages();
parse.process(u, new File("."));
} catch (Exception e)
{
e.printStackTrace();
}
}
}
Search WWH ::




Custom Search