Skip to content

Commit e2b226a

Browse files
authored
A simple web page source code viewer or scraper
1 parent d36fa4d commit e2b226a

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

Web_Page_Source_Viewer.java

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import java.awt.*;
2+
import java.awt.event.*;
3+
import java.io.InputStream;
4+
import java.net.*;
5+
public class SourceGetter extends Frame implements ActionListener{
6+
TextField tf;
7+
TextArea ta;
8+
Button b;
9+
Label l;
10+
SourceGetter(){
11+
super("Source Getter Tool - Javatpoint");
12+
l=new Label("Enter URL:");
13+
l.setBounds(50,50,50,20);
14+
15+
tf=new TextField();
16+
tf.setBounds(120,50,250,20);
17+
18+
b=new Button("Get Source Code");
19+
b.setBounds(120, 100,120,30);
20+
b.addActionListener(this);
21+
22+
ta=new TextArea();
23+
ta.setBounds(120,150,250,150);
24+
25+
add(l);add(tf);add(b);add(ta);
26+
setSize(400,400);
27+
setLayout(null);
28+
setVisible(true);
29+
}
30+
public void actionPerformed(ActionEvent e){
31+
String s=tf.getText();
32+
if(s==null){}
33+
else{
34+
try{
35+
URL u=new URL(s);
36+
URLConnection uc=u.openConnection();
37+
38+
InputStream is=uc.getInputStream();
39+
int i;
40+
StringBuilder sb=new StringBuilder();
41+
while((i=is.read())!=-1){
42+
sb.append((char)i);
43+
}
44+
String source=sb.toString();
45+
ta.setText(source);
46+
}catch(Exception ex){System.out.println(e);}
47+
}
48+
}
49+
public static void main(String[] args) {
50+
new SourceGetter();
51+
}

0 commit comments

Comments
 (0)