封⾯就是图⽚,62616964757a686964616fe59b9ee7ad9431333337616466⽤java的类抓取图⽚即可package tool;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.HttpURLConnection;
import java.URL;
import java.util.LinkedList;
import java.util.List;好的专业
import Matcher;
import Pattern;
mp3歌曲怎么下载import javax.swing.ImageIcon;
好玩网络游戏排行榜import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.SwingUtilities;
import Style;
import StyleConstants;
import StyleContext;
import StyledDocument;
public class ImageViewer extends JFrame
{
private static final String DOWNLOADPATH = "download/";
JTextPane textPane = new JTextPane ();
LinkedList initString = new LinkedList ();
LinkedList initStyles = new LinkedList ();
LinkedList path = new LinkedList ();
public ImageViewer ()
{
setTitle ("图⽚预览下载器 v1.0");
setLayout (new BorderLayout ());
setSize (500, 300);
setLocationRelativeTo (null);
setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
韩庚和始源}
private void addComponents ()
{
final JTextField urltField = new JTextField ();
JPanel right = new JPanel (new FlowLayout (FlowLayout.RIGHT, 0, 0));
final JButton go = new JButton ("GO");
textPane.setEditable (false);
JScrollPane content = new JScrollPane (textPane);
家用净水器十大品牌go.addActionListener (new ActionListener ()
{
@Override
public void actionPerformed ( ActionEvent e )
{
String url = Text ().trim ();
resolveHTML (url, "utf8", "(?i)\\]*src[\\=\\s\'\"]+([^\\>\'\"]+)[\'\"]?[^\\>]*\\>"); }
});
JPanel up = new JPanel (new BorderLayout ());
up.add (urltField, BorderLayout.CENTER);
right.add (go);
JButton download = new JButton ("DOWNLOAD");
{
@Override
public void actionPerformed ( ActionEvent e )
{
downloadImages ();
}
});
right.add (download);
up.add (right, BorderLayout.EAST);
add (up, BorderLayout.NORTH);
add (content, BorderLayout.CENTER);
}
private void downloadImages ()
叶全真电影
{
File fp = new File (DOWNLOADPATH);
if (!fp.exists ())
{
fp.mkdir ();
}
for ( int i = 0; i
{
try
{
String p = (i);
URL url = new URL (p);
HttpURLConnection huc = (HttpURLConnection) url.openConnection (); huc.setRequestMethod ("GET");
huc.setConnectTimeout (5 * 1000);
InputStream is = InputStream ();
ByteArrayOutputStream baos = new ByteArrayOutputStream ();
byte[] buffer = new byte[1024];
int len = -1;
while (( len = is.read (buffer) ) != -1)
baos.write (buffer, 0, len);
}
baos.flush ();
baos.close ();
is.close ();
huc.disconnect ();
byte[] data = ByteArray ();
String name = p.substring (p.lastIndexOf ("/") + 1, p.length ());
name = ains (".") ? name : name + ".jpg";
FileOutputStream fos = new FileOutputStream (new File (DOWNLOADPATH + name)); fos.write (data);
fos.flush ();
fos.close ();
}
catch (Exception e)
{
continue;
}
}
}
private void loadImages ( List initString, List initStyles, List url )
{
try
{
StyledDocument doc = StyledDocument ();
addStylesToDocument (doc, url, initStyles);
for ( int i = 0; i
{
doc.insertString (Length (), (i), Style ( (i)));
}
}
catch (Exception e)
}
protected void addStylesToDocument ( StyledDocument doc, List url, List initStyles )
{
Style def = DefaultStyleContext ().getStyle (StyleContext.DEFAULT_STYLE); for ( int i = 0; i
{
Style s = doc.addStyle ( (i), def);
StyleConstants.setAlignment (s, StyleConstants.ALIGN_CENTER);
ImageIcon icon = createImageIcon ( (i));
if (icon != null)
{
StyleConstants.setIcon (s, icon);
}
}
}
protected static ImageIcon createImageIcon ( String url )
{
URL imgURL = null;
try
{
imgURL = new URL (url);
if (imgURL != null)
{
return new ImageIcon (imgURL);
}
}
catch (Exception e)
{}
return null;
}
private void resolveHTML ( String spec, String charsetName, String regex )
{
try
发布评论