困扰了我快半年的问题终于在春节当天解决,散分庆祝!

java_road 2007-02-19 02:29:06
曾在
http://community.csdn.net/Expert/topic/5341/5341889.xml?temp=.3290979
上留过一个问题,花了我100分,最终还是没有头绪,问题如下:
网页动态屏蔽:
假设你现在在看我的帖子,看到的是屏蔽前的网页,但是,当运行网页动态屏蔽的java程序后,你所看到的却是

主  题: 高手请问:谁知道网页动态屏蔽的原理?
*** ***: java_road () Blog
等  级:
信 誉 值: 100
所属社区: Java J2SE / 基础类
问题****: 100
***次数: 4
发表***: 2007-02-06 14:06:13
现在程序源代码如下,其实这个功能还是有很多作用的,而且我又提倡开源,所以把代码公布出来,贡大家参考,当然功能的大部分工作还有待以后来完善!!!
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
import java.util.regex.*;
import javax.swing.event.*;
class Win1 extends JFrame implements ActionListener,Runnable
{
JButton button;
URL url, newURL;
JTextField text;
JEditorPane editPane;
byte b[]=new byte[118];
Thread thread;
Container con=null;
JPanel p;
public Win1()
{
text=new JTextField(20);
editPane=new JEditorPane();
editPane.setEditable(false);
button=new JButton("确定");
button.addActionListener(this);
thread=new Thread(this);
p=new JPanel();
p.add(new JLabel("输入网址:"));
p.add(text);
p.add(button);
con=getContentPane();
con.add(new JScrollPane(editPane),BorderLayout.CENTER);
con.add(p,BorderLayout.NORTH);
setBounds(60,60,460,380);
setVisible(true);
validate();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e)
{
if(!(thread.isAlive()))
thread=new Thread(this);
try{
thread.start();
}
catch(Exception ee)
{
text.setText("我正在读取"+url);
}
}
public void run()
{
try {
int m=-1;
editPane.setText(null);
url=new URL(text.getText().trim());
InputStream in=url.openStream();
File file=new File("temp.html");
ByteArrayOutputStream write=new ByteArrayOutputStream ();
while((m=in.read(b))!=-1)
{
write.write(b,0,m);
}
write.close();
in.close();
byte content[]=write.toByteArray();
String str=new String(content);
Pattern pattern;
Matcher match;
// pattern=Pattern.compile("<IMG.*>",Pattern .CASE_INSENSITIVE);
// match=pattern.matcher(str);
//str=match.replaceAll("");
pattern=Pattern.compile("新闻",Pattern .CASE_INSENSITIVE);
match=pattern.matcher(str);
str=match.replaceAll("****");
byte cc[]=str.getBytes();
ByteArrayInputStream inByte=new ByteArrayInputStream(cc);
FileOutputStream out=new FileOutputStream(file);
byte dd[]=new byte[1024];
while((m=inByte.read(dd,0,1024))!=-1)
{
out.write(dd,0,m);
}
out.close();
inByte.close();
newURL=file.toURL();
con.removeAll();
editPane=new JEditorPane();
editPane.setEditable(false);
editPane.addHyperlinkListener(new HyperlinkListener()
{
public void hyperlinkUpdate(HyperlinkEvent e)
{
if(e.getEventType()==
HyperlinkEvent.EventType.ACTIVATED)
{
try{
URL linkURL=e.getURL();
editPane.setPage(linkURL);
}
catch(IOException e1)
{
editPane.setText(""+e1);
}
}
}
}
);
editPane.setPage(newURL);
con.add(p,BorderLayout.NORTH);
con.add(new JScrollPane(editPane),BorderLayout.CENTER);
con.validate();
validate();
}
catch(MalformedURLException e1)
{
text.setText(""+e1);
return;
}
catch(IOException e1)
{
text.setText(""+e1);
return;
}
}
}
public class Win
{
public static void main(String args[])
{
new Win1();
}
}
...全文
433 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
guoxyj 2007-02-25
  • 打赏
  • 举报
回复
每看懂什么目的
haisenmai 2007-02-25
  • 打赏
  • 举报
回复
:)
lw9313 2007-02-25
  • 打赏
  • 举报
回复
jf
beauty4 2007-02-25
  • 打赏
  • 举报
回复
恭喜~
lixiaoxue85 2007-02-25
  • 打赏
  • 举报
回复
恭喜:)
For_suzhen 2007-02-24
  • 打赏
  • 举报
回复
JF and UP
新的一年共同进步啊
Moon 2007-02-24
  • 打赏
  • 举报
回复
恭喜:)
接分~~~
ts2794 2007-02-24
  • 打赏
  • 举报
回复
接分
pop3696 2007-02-24
  • 打赏
  • 举报
回复
是什么原理呢,简单说明一下把,
http://community.csdn.net/Expert/topic/5341/5341889.xml?temp=.3290979
这个帖已经没了??
haitao8686 2007-02-23
  • 打赏
  • 举报
回复
接分来迟 恭喜!
maguang54 2007-02-23
  • 打赏
  • 举报
回复
恭喜!新年快乐
emin_lee 2007-02-23
  • 打赏
  • 举报
回复
恭喜:)
约翰羊 2007-02-20
  • 打赏
  • 举报
回复
我的猪年第一个接分贴。。。。。
恭喜楼主,我自己也庆祝一下!
interpb 2007-02-19
  • 打赏
  • 举报
回复
接分来迟 呵呵

猪年快乐
antsmoving 2007-02-19
  • 打赏
  • 举报
回复
恭喜 接分 :)
shan1119 2007-02-19
  • 打赏
  • 举报
回复
新年快乐~
EddieO05 2007-02-19
  • 打赏
  • 举报
回复
接分
Eddie005 2007-02-19
  • 打赏
  • 举报
回复
新年快乐~
Eddie005 2007-02-19
  • 打赏
  • 举报
回复
恭喜~

23,404

社区成员

发帖
与我相关
我的任务
社区描述
Java 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧