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 4329702
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:51:34+00:00 2026-05-21T09:51:34+00:00

I am parsing out specific information from a website into a file. Right now

  • 0

I am parsing out specific information from a website into a file. Right now the program I have looks at a webpage, and find the right HTML tag and parses out the right contents. Now I want to further filter these “results”.

For example, on the site : http://allrecipes.com/Recipe/Slow-Cooker-Pork-Chops-II/Detail.aspx

I am parsing out the ingredients which are located in < div class=”ingredients”…> tag. This parser does the job nicely but I want to further process these results.

When I run this parser, it removes numbers, symbols, commas, and slash(\ or /) but leaves all text. When I run it on the website I get results like:

cup olive oil
cup chicken broth
cloves garlic minced
tablespoon paprika

Now I want to further process this by removing stop words like “cup”, “cloves”, “minced”, “tablesoon” among others. How exactly do I do this? This code is written in python and I am not very good at it, and I am just using this parser to get information which I can manually enter but I would rather not.

Any help on how to do this in detail would be appreciated! My code is below: how would I do this?

Code:

import urllib2
import BeautifulSoup

def main():
    url = "http://allrecipes.com/Recipe/Slow-Cooker-Pork-Chops-II/Detail.aspx"
    data = urllib2.urlopen(url).read()
    bs = BeautifulSoup.BeautifulSoup(data)

    ingreds = bs.find('div', {'class': 'ingredients'})
    ingreds = [s.getText().strip('123456789.,/\ ') for s in ingreds.findAll('li')]

    fname = 'PorkRecipe.txt'
    with open(fname, 'w') as outf:
        outf.write('\n'.join(ingreds))

if __name__=="__main__":
    main()
  • 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-05-21T09:51:35+00:00Added an answer on May 21, 2026 at 9:51 am
    import urllib2
    import BeautifulSoup
    import string
    
    badwords = set([
        'cup','cups',
        'clove','cloves',
        'tsp','teaspoon','teaspoons',
        'tbsp','tablespoon','tablespoons',
        'minced'
    ])
    
    def cleanIngred(s):
        # remove leading and trailing whitespace
        s = s.strip()
        # remove numbers and punctuation in the string
        s = s.strip(string.digits + string.punctuation)
        # remove unwanted words
        return ' '.join(word for word in s.split() if not word in badwords)
    
    def main():
        url = "http://allrecipes.com/Recipe/Slow-Cooker-Pork-Chops-II/Detail.aspx"
        data = urllib2.urlopen(url).read()
        bs = BeautifulSoup.BeautifulSoup(data)
    
        ingreds = bs.find('div', {'class': 'ingredients'})
        ingreds = [cleanIngred(s.getText()) for s in ingreds.findAll('li')]
    
        fname = 'PorkRecipe.txt'
        with open(fname, 'w') as outf:
            outf.write('\n'.join(ingreds))
    
    if __name__=="__main__":
        main()
    

    results in

    olive oil
    chicken broth
    garlic,
    paprika
    garlic powder
    poultry seasoning
    dried oregano
    dried basil
    thick cut boneless pork chops
    salt and pepper to taste
    

    ? I don’t know why it’s left the comma in it – s.strip(string.punctuation) should have taken care of that.

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

Sidebar

Related Questions

I been working on parsing out bookmarks from an export file generated by google
If I'm parsing something like the Apache website, I have one specific problem that
I'm parsing an xml file and i've been trying to strip out the whitespace
I am parsing some HTML source. Is there a regex script to find out
I'm parsing text from a file and storing it in a string. The problem
I have an existing SQL Server database, where I store data from large specific
I am parsing data from a website via xml that always changes so I
I am trying to parse out specific information within tags. For example, on the
I know how about the capture part in wireshark. Parsing and figuring out the
Parsing a text file in vb.net and need to locate the latitude and longitude

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.