Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7983871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:05:35+00:00 2026-06-04T11:05:35+00:00

I need to extract the 10 most frequent words from a text using a

  • 0

I need to extract the 10 most frequent words from a text using a pipe (and any additional python scripts as needed); output being a block of all-caps words separated by a space.
This pipe needs to extract text from any external file: I’ve managed to get it to work on .txt files, but I also need to be able to input a URL and have it do the same thing with that.

I have the following code:

alias words="tr a-zA-Z | tr -cs A-Z | tr ' ' '\012' | sort -n | uniq -c | 
sort -r | head -n 10 | awk '{printf \"%s \", \$2}END{print \"\"}'" (on one line)

which, with cat hamlet.txt | words gives me:

TO THE AND A  'TIS THAT OR OF IS

To make it more complicated, I need to exclude any ‘function’ words: these are ‘non-lexical’ words like ‘a’, ‘the’, ‘of’, ‘is’, any pronouns (I, you, him), and any prepositions (there, at, from).

I need to be able to type htmlstrip http://www.google.com.au | words and have it print out like the above.

For the URL-opening:
The python script I’m trying to figure out (let’s call it htmlstrip) strips any tags from the text, leaving only ‘human readable’ text. This should be able to open any given URL, but I can’t figure out how to get this to work.
What I have so far:

import re
import urllib2
filename = raw_input('File name: ')
filehandle = open(filename)
html = filehandle.read()

f = urllib2.urlopen('http://') #???
print f.read()

text = [ ]
inTag = False


for ch in html:
    if ch == '<':
        inTag = True
    if not inTag:
        text.append(ch)
    if ch == '>':
        inTag = False

print ''.join(text)

I know this is both incomplete and probably incorrect – any guidance would really be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T11:05:37+00:00Added an answer on June 4, 2026 at 11:05 am

    You can use scrape.py and regular expressions like this:

    #!/usr/bin/env python
    
    from scrape import s
    import sys, re
    
    if len(sys.argv) < 2:
        print "Usage: words.py url"
        sys.exit(0)
    
    s.go(sys.argv[1]) # fetch content
    text = s.doc.text # extract readable text
    text = re.sub("\W+", " ", text) # remove all non-word characters and repeating whitespace
    print text
    

    And then just:
    ./words.py http://whatever.com

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to extract data from HTML-files. The files in question are, most likely,
I need to extract parts of a string using regex in Python. I'm good
I need to take a paragraph of text and extract from it a list
I process rather large matrices in Python/Scipy. I need to extract rows from large
I have several array to deal with. I need to extract the most duplicate
I need to extract all MP3 titles from a fuzzy list in a list.
I need to extract all the tags from an HTML file, In such a
I need to extract the zip code from a string. The string looks like
I need to extract data from a structure and put it into a list,
I need to extract data from a source that presents it in one of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.