Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

If I try wget on a webpage, I am getting the page as html. Is it possible to retrieve only text of a file without associated html ? (This is required for me since some of the HTML pages contains c program is getting downloaded with html tags. I have to open it in browser and manually copy the text to make a .c file.)

share|improve this question
    
Actually it is possible, but you need to write some function that will parse the code from the page and save it as .c. It is not hard, but it depends on page structure. If you provide a link may be somebody will help you with exact code. Otherwise sed or perl are your friends. –  rush Jul 9 '12 at 8:28
add comment

1 Answer

up vote 11 down vote accepted

wget will only retrieve the document. If the document is in HTML, what you want is the result of parsing the document.

You could, for example, use lynx -dump -nolist, if you have lynx around.

lynx is a lightweight, simple web browser, which has the -dump feature, used to output the result of the parsing process. -nolist avoids the list of links at the end, which will appear if the page has any hyperlinks.

As mentioned by @Thor, elinks can be used for this too, as it also has a -dump option (and has -no-references to omit the list of links). It may be especially useful if you walk across some site using -sigh- frames (MTFBWY).

Also, keep in mind that, unless the page is really just C code with HTML tags, you will need to check the result, just to make sure there's nothing more than C code there.

share|improve this answer
    
Or use elinks which has support for frames. Use -no-references to achieve the same effect as nolist for lynx. –  Thor Jul 12 '12 at 23:01
    
@Thor, thanks, I updated the answer to mention that. –  njsg Aug 8 '12 at 8:30
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.