Solved

how to download a webpage including images,applets,..

Posted on 2004-09-15
12
155 Views
Last Modified: 2012-05-05
Hi,

How can I write a routine that will download a web page and store it on my hard disk.  It also has to download all associated objects including Images,Applets, etc ?

for eg:if i type "www.yahoo.com" ,i should download the complete webpage including all.

i have tried with the following code i can not able to get the images

                        URL url=new URL("http://www.kumudam.com");
                        InputStream conn=url.openStream();
              BufferedReader input = new BufferedReader(new InputStreamReader(conn));
                    String line ;
                        byte data[]= new byte[1000];
                        int size = input.read();
                        System.out.println(size);
                        while ((line = input.readLine()) != null)
                  
                            System.out.println(line);
                            input.close();
Thanks in advance
0
Comment
Question by:vihar123
  • 4
  • 3
  • 2
  • +1
12 Comments
 
LVL 92

Accepted Solution

by:
objects earned 250 total points
Comment Utility
you'll need to parse the html, here's an example showing how to extract all the links.

http://www.javaalmanac.com/egs/javax.swing.text.html/GetLinks.html

You can then download the data pointed to in the link.
0
 
LVL 21

Expert Comment

by:MogalManic
Comment Utility
objects is right.

When a browser access a page, it loads the page and all of its assocated objects through a series of GETs.  The first get is the HTML of course.  Then the browser parses the HTML and as it encounters a tag that refers to an external resource it issues another GET to retrieve and render the resource.  Your code would have to do something simalar.
0
 
LVL 18

Expert Comment

by:armoghan
Comment Utility
and when you get the image links as described by the link given by objects,
you can save the images to local file system like

http://forum.java.sun.com/thread.jsp?thread=433352&forum=31&message=1940583

basically you would be looking for
HTML.Attribute.IMG

you will need to find the <APPLET tag as well for downloading applets


0
 

Author Comment

by:vihar123
Comment Utility
hi objects,

i have seen the same code and tried i am getting javax.swing.text.changedcharsetexception,i cannot able to rectify.

pls help me  :)
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
doc.putProperties("IgnoreCharacterSet", new Boolean(true));
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:vihar123
Comment Utility
hi,
this HTML parser is not working for all websites.pls help me out :)
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
yes if it not standard html, or uses recent features it will have problems.
0
 

Author Comment

by:vihar123
Comment Utility
hi objects,
what to do in this case? any idea..
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
you need to look at a different parser, perhaps a commercial one.
0
 
LVL 18

Assisted Solution

by:armoghan
armoghan earned 250 total points
Comment Utility
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
strCopies  challenge 17 73
Unable to start eclipse ? 17 82
Java array passed to SQL where clause 23 38
eclipse formatting 6 38
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now