A little problem getting the style tag of a html file seperate from rest

I'm making a program that will take in a URL and then search through that URL for all a, link, embed, frame, and img tags, find their sources, and download them. I also want to search through the style and find anything that uses a URL (ex. background-image:url('somepic.jpg')) and download that file. In the end, you should be able to go to the directory you saved it all in, open index.html, and see an exact replica of the original site. Now, my problem is that my program isn't getting the style tag's contents. Here's my code: import java.io.*;
import java.util.*;
import java.net.*;
public class Test
     //-->>>> MAIN <<<<--//
     public static void main(String...a)
          try{
               System.out.print("Enter URL: ");
               String target = new Scanner(System.in).next();
               URL url = null;
               try{
                    url = new URL(target);
               }catch(MalformedURLException x){
                    url = new URL("http://" + target);
               Scanner scan = new Scanner(url.openStream());
               scan.useDelimiter("<");
               ArrayList<String> tokens = new ArrayList<String>();
               while(scan.hasNext())
                    String str = scan.next();
                    str = str.trim();
                    Scanner tags = new Scanner(str);
                    if(tags.hasNext())
                         String tag = tags.next();
                         if(tag.equalsIgnoreCase("a") || tag.equalsIgnoreCase("img") || tag.equalsIgnoreCase("link") || tag.equalsIgnoreCase("embed") || tag.equalsIgnoreCase("frame"))
                              tokens.add(str);
                         else if(tag.equalsIgnoreCase("style"))
                              tokens.add(str);// This isn't adding anything
               for(String str : tokens)
                    System.out.println(str);
          }catch(UnknownHostException x){
               System.err.println("Host not found.");
          }catch(Exception x){
               x.printStackTrace();
     //-->>>> FindURLAttributes <<<<--// <--- Under construction
     private static ArrayList<String> findURLAttributes(String tag)
          ArrayList<String> tokens = new ArrayList<String>();
          tokens.add(tag);
          return tokens;
}

I've never tried it, but it seems like using an existing html parser would be a lot easier. I've worked with xml dom parsers, and it's not really that hard. I don't imagine working with an html dom would be too difficult either, at least it wouldn't be as hard as doing it by hand. Google for java html parser and see if any of them suit your needs.

Similar Messages

  • How to get list of tags in my html file?

    Hi,
    I am having a html file.
    I would like to display the list of tags and the names in the html file.
    For example, I am having a tag <input> and defined the tag name as "Inp1".
    So, I want to display the list of all tags and its names.
    Thank you,
    Regards,
    Gowtham Sen

    Is this an oversight in the library specification?
    Why does the tld file not contain any tag interrelationship information when the tags java api provide all the mechenism handle nesting.
    I have a tag library with a large number of tags which form a hierarchy reflecting the design of the library and its components.
    As the meta information ( tld ) does not contain any information about this hierarchy, the user is left clueless as to the composition of the tags.
    Also this directly affects all jsp design and editing tools, making features like code completion etc almost useless.
    Anyone from the tag library spec team ???

  • Is it possible to get the style, font and related info of a paragraph of a in design file and write it on the same in design file  on the  left side

    Is it possible to get the style, font and related info of a paragraph text  of a in design file and write  all the stuff on the same in design file  on the  left side with small fonts 
    as
    Lets  this is a text in in design file    :
    style : abc                      we are going to check the  condition  Agence Wallonne pour la Promotion d'une Agricultur we are going to check the  condition  Agence Wallonne pour la    font 12                                  d'une Agricultu we are going to check the  condition  Agence Wallonne pour la Promotion d'une Agricultu
    style : xyz                      we are going to check the  condition  Agence Wallonne pour la Promotion d'une Agricultur we are going to check the  condition  Agence Wallonne pour la    font 10                                  d'une Agricultu we are going to check the  condition  Agence Wallonne pour la Promotion d'une Agricultu

    Hi Poojith
    Not sure if this would solve your requirment but just in case might be helpful:
    1. We can mix up the HTML and HTMLB components in the JSP Page. However, can access only the HTMLB components in the controller. The following link refers to what customizations are offered by the HTMLB framework:
    [http://www.sapdesignguild.org/resources/htmlb_guidance/]
    2. Another option would be to use AbstractPortalComponents or a simple web app if that's feasible. (where custom UI themes, css and layout are more in control of the developers.)
    Thanks
    Deepak

  • I am trying to connect my Sony DCR-TRV350 to iMovie so that I can make DVD's from family videos.  I am having problems getting the video camera connected.  Any advice on how to do this?

    I am trying to connect my Sony DCR-TRV350 to iMovie so that I can make DVD's from family videos.  I am having problems getting the video camera connected.  Any advice on how to do this?

    What happens when, after you connect your cam, you go to File > Import Media?
    But before that, does your cam require you to export your video files upon USB connection? I have a JVC Everio HD and I have to "Export to Library" from the cam's menu first-thing. This was true even in prior iMovie versions.

  • Unknown error: there was a problem getting the status directory!

    Hi, Folks,
    I followed the instructions on this page :http://deimos.apple.com/rsrc/doc/iTunesUAdministrationGuide/AddingContent/chapte r_12_section_6.html#//apple_ref/doc/uid/AdminGuide-CH22-SW5, and try to upload a file to our university's Itunes U site.
    I believe got every step right, but server return a error message: "unknown error: there was a problem getting the status directory". Any suggestion or information will be helpful.
    Thanks
    Youjun

    Forgot to mention.  ours is a public site but the collection I am trying to access is not published.
    Youjun

  • Using Dreamweaver CC 2014.1.1, when I select a set of paragraphs to turn into a Definition List, and select Format - Lists - Definition Lists, I get the dl tags but do not get the dt or dd tags?

    I have used this before in earlier versions of DW and it worked fin.  I tried tonight with CC 2014.1.1 in either design view or in codeview with the same results.  I would select the text from the starting <p> tag to the ending </p> tag, and then in the menu choose Format - List - Definition List and only get the <dl> tags.  Anyone else experience this?
    Thanks!

    That's how it works in CS6, too.  And it is not just for definition lists.  That is the expected outcome no matter which list type you use.   DW doesn't know where the DTs and DDs begin and end because you've highlighted an entire paragraph and asked DW to format it as a DL.
    I typically code my own Definition Lists.  It's faster.
    Nancy O.

  • How to get the anchor tag values in next jsp

    Hey all,
    I have two jsp files.
    in first jsp,
    I am getting the resultset.
    I am setting the resultset to the anchor tag.
    below is the code...
    <a target="_top" rel="contents" rev="contents" class="fordynamiclabel" href="ASCMasterTwo.jsp"><%=rSet.getString(1) %></a></td>
    whenever he click on any anchor tag,
    It will goes to ACSMasterTwo.jsp page for edit the compleate record.
    how to get the anchor tag value in that page...
    Please help me on this.

    You have to pass a parameter. An id is good.
    Of course you have to get an id from somewhere in the result set right?
    <a target="_top" rel="contents" rev="contents" class="fordynamiclabel" href="ASCMasterTwo.jsp?id=<%= rSet.getString("id") %>"><%=rSet.getString(1) %></a></td>Then you call
    request.getParameter("id");
    and look up the values related to that id in the database.

  • Having a problem getting the Viber 4 digit SMS access code.

    Having a problem getting the 4 digit SMS access code. Even when I click on the get code tab, It says an error has occurred during the Viber activation process.

    Is Viber an app? have you tried contacting the developer?

  • How to get the measure of area in HTML by Java

    Hi all,
    I know in JavaScript,
    clientheight and clientlength can get the measure of area of HTML element, but how can I implement this in Java?
    I understand I may need to have a much complete browser component first (for weak HTML rersolving in JDK), but I would like to know how HTML rendering works in JEditorPane and JTextPane, maybe that can help me solve the problem.
    Appreciate for any suggestions and references.
    Best regards,
    KaiLiang

    Thanks lots!!
    So, the View class in JDK does not deal with the width and length information, does it?
    If I want to solve my problem, I have to customize View class to make it can deal with width and length information.
    Is it possible to get width and lenth of elements when JEditorPane render the HTML?

  • Firefox will not show links to flv files. I get the error message for each flv file: "File not found. Firefox can't find the file at (path) .flv." Any mov and swf files in this same path will show. I can see the videos in Safari so the paths are correct.

    Firefox will not show links to flv files. I get the error message for each flv file: "File not found. Firefox can't find the file at http:// (path) .flv." Any mov and swf files in this same path will show. I can see the videos in Safari so the paths are correct.

    Is this a webpage that contains a link to a flv file? Please post a link to the page and tell us which link(s) are the problem flv files or else post a link to the .flv file itself.
    Alternately, click on one of the sample FLV File links on this page and tell us exactly what happens:
    http://www.mediacollege.com/adobe/flash/video/tutorial/example-flv.html
    It might also help if you post the exact error message, including the path to the flv file.
    '''Note:'''
    Depending on how you have Firefox set up, clicking on a FLV File link will either save the FLV file to your computer or Firefox may open it automatically in an external application right after downloading (Firefox may ask you first). Firefox itself can't play FLV files so you need a "helper" application (or a plugin for flv files, if ther is one. You can see if Firefox is already set up to download or open FLV files by going to Firefox Preferences and looking in the Applications list. Find the FLV file type in the list and, if the action is "Open with", it should show the application that can play FLV files (e.g., VLC Media Player or Perian). See [[Managing filetypes]] for more information.

  • Since I signed up for icloud, I can't get into my iweb application. I get the following message   Can't open file "/Volumes/pnoon1/Band Stufff/Domain.sites2."

    Since I signed up for icloud, I can't get into my iweb application. I get the following message 
    Can’t open file “/Volumes/pnoon1/Band Stufff/Domain.sites2.”
    Any one have any clues ????

    Hi!
    I encountered a problem a few weeks ago which is a bit like yours. In my case my Apple ID stopped working after I upgraded to Mountain Lion. I finally found out it was because of the fact that my Apple ID has in fact been an alias within my much older MobileMe/iCloud account. And they weren't able to merge or reset the account at first. It took me a lot of mails and a few calls to get them to resetting the account and changing my Apple ID (for the Apple Store, iTunes, etc.) to a different, non-iCloud related email adress.
    Anyway, maybe you can call the Apple Support and kindly ask them to reset the password for this ominous @me.com account so you can finally start using it.
    Did you try logging into iCloud using your adress with the appendix @me.com because not everybody has got the @icloud.com ending yet. Technically it's no problem to create a new iCloud account. I can understand though that you'd like to get "your name" back .

  • How Do I Use the Help Tag/Help Path in LabVIEW to Link to a Specific tag in an HTML File?

    Is there any way to point user to a tag in an HTML file when he click "Click here for more help" ?
    Message Edited by zou on 03-08-2007 02:38 PM
    George Zou
    http://webspace.webring.com/people/og/gtoolbox
    Attachments:
    a.png ‏18 KB

    George,
    I believe you are correct in saying that there is no way to link directly to a specific anchor tag within an html file from the context help.
    I would encourage you to visit our Product Suggestion Center if this is a feature you would like to recommend that our R&D team consider for future versions of LabVIEW.
    Is it possible for you to create a .chm file?  Or perhaps you could have some kind of "table of contents" at the top of your .html help file.  This would require an extra click by the user but may be an option for you.
    Regards,
    Simon H
    Applications Engineer
    National Instruments
    http://www.ni.com/support/

  • How to get the values of all elements and sub elements from  following xml

    how to get the values of all elements and sub elements from following xml...
    <?xml version="1.0" encoding="UTF-8" ?>
    <List_AML_Finacle xmlns="http://3i-infotech.com/Cust_AML_Finacle.xsd"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://3i-infotech.com/Cust_AML_Finacle.xsd List_AML_Finacle.xsd">
    <TransactionID>TransactionID</TransactionID>
    <Match>
    <Src_Matched_Field>Src_Matched_Field</Src_Matched_Field>
    <List_Matched_Field>
    <FSFM_Matches>
    <NUMBER>NUMBER</NUMBER>
    <TERROR>TERROR</TERROR>
    <TU>TU</TU>
    <NAMEU>NAMEU</NAMEU>
    <DESCRIPT>DESCRIPT</DESCRIPT>
    <KODCR>KODCR</KODCR>
    <KODCN>KODCN</KODCN>
    <AMR>AMR</AMR>
    <ADDRESS>ADDRESS</ADDRESS>
    <SD>SD</SD>
    <RG>RG</RG>
    <ND>ND</ND>
    <VD>VD</VD>
    <GR>GR</GR>
    <YR>YR</YR>
    <MR>MR</MR>
    <CB_DATE>CB_DATE</CB_DATE>
    <CE_DATE>CE_DATE</CE_DATE>
    <DIRECTOR>DIRECTOR</DIRECTOR>
    <FOUNDER>FOUNDER</FOUNDER>
    <TERRTYPE>TERRTYPE</TERRTYPE>
    </FSFM_Matches>
    <OfacMatchDetails>
    <UID>UID</UID>
    <TITLE>TITLE</TITLE>
    <SDNTYPE>SDNTYPE</SDNTYPE>
    <REMARKS>REMARKS</REMARKS>
    <ID_UID>ID_UID</ID_UID>
    <IDTYPE>IDTYPE</IDTYPE>
    <IDNUMBER>IDNUMBER</IDNUMBER>
    <IDCOUNTRY>IDCOUNTRY</IDCOUNTRY>
    <ISSUEDATE>ISSUEDATE</ISSUEDATE>
    <EXPIRATIONDATE>EXPIRATIONDATE</EXPIRATIONDATE>
    <ADDRESS1>ADDRESS1</ADDRESS1>
    <ADDRESS2>ADDRESS2</ADDRESS2>
    <ADDRESS3>ADDRESS3</ADDRESS3>
    <CITY>CITY</CITY>
    <STATEORPROVINCE>STATEORPROVINCE</STATEORPROVINCE>
    <POSTALCODE>POSTALCODE</POSTALCODE>
    <COUNTRY>COUNTRY</COUNTRY>
    </OfacMatchDetails>
    </List_Matched_Field>
    </Match>
    </List_AML_Finacle>

    avoid multi post
    http://forum.java.sun.com/thread.jspa?threadID=5249519

  • Itunes will not install. I get the error message "Error writing to file: C:\Program Files\Common Files\Apple\Mobile Device Support\com.apple.IE.client_main.dll     Verify that you have access to that directory."

    Itunes will not install. I get the error message "Error writing to file: C:\Program Files\Common Files\Apple\Mobile Device Support\com.apple.IE.client_main.dll     Verify that you have access to that directory."

    That one's consistent with disk/file damage. The first thing I'd try with that is running a disk check (chkdsk) over your C drive.
    XP instructions in the following document: How to perform disk error checking in Windows XP
    Vista instructions in the following document: Check your hard disk for errors
    Windows 7 instructions in the following document: How to use CHKDSK (Check Disk)
    Select both Automatically fix file system errors and Scan for and attempt recovery of bad sectors, or use chkdsk /r (depending on which way you decide to go about doing this). You'll almost certainly have to schedule the chkdsk to run on startup. The scan should take quite a while ... if it quits after a few minutes or seconds, something's interfering with the scan.
    Does the chkdsk find/repair any damage? If so, can you get an install to go through properly afterwards?

  • How do i get the hp officejet pro 8600 premium to print from my ipad2 using airprint?

    how do i get the hp officejet pro 8600 premium to print from my ipad2 using airprint? The iPad does not see the printer.

    Hi RiverBirch,
    What brand and model is your router?
    First, connect your printer to your router.
    1. From printer front panel, press Wireless>Wireless Settings>Wireless Setup Wizard and follow the onscreen instructions to successfully connect your printer with an IP address.
    Secondly, connect your iPad to the same router.
    1. Connect your iPad to the Internet and download the free HP ePrint Home & Biz app from the apps store.
    2. Connect your iPad to the same network as the printer. Settings>Network.
    3. Use the new HP Home & Biz app to print and scan photos or docs from your iPad!
    Alternatively, you can also perform Airprint on the iPad thru the wireless network from the Photos menu in your iPad.
    Please click the blue Kudos star in the post that helped you.

Maybe you are looking for

  • DELL XPS 6000 with Audigy2ZS..No so

    <font face="Baskerville Old Face" size="5">?I have a Dell XPS 6000 Dimension desktop. Win XP. The sound card is a (Soundblaster 2ZS.) The integrated audio onboard is?(RealtekAC 97 Audio.)?I heard the Windows Startup theme,but when I play a song in Wi

  • Best uses of 5G's

    I would love to see how early Video iPod owners are using their units. ie..playback video onto LCD tv screens in their car....

  • Flex Classes be used in Flash CS3 pro???

    I wrote some classes in Flex that use the Canvas Class. I want to use it in a Flash widget I'm making, but when I try and import and run my class in CS3, it says this: 1017: The definition of base class Canvas was not found. How can I set up a connec

  • JSF - spring - hibernate and session

    Hi, I'm currently using hibernate spring and JSF 1/ the first problem In the JSF common header page I try to test if a bean is in the session scope in order to show login or logout link, and the test always fails : the logout link is always displayed

  • SAP Lumira displays "Not a subscription user" for ArcGIS Online account

    Hello, I have created free trial ArcGIS online account and specified this user in SAP Lumira 1.17.1 Preferences / GEO Map Service. But when I try to visualize my Location data on Geo Map visualization I get an error message "Not a subscription user".