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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:54:38+00:00 2026-06-01T07:54:38+00:00

My overall goal is isolate tags that contain a certain word in the text

  • 0

My overall goal is isolate tags that contain a certain word in the text and have only those print to a text file.

So far, I have been able to extract particular the tag, in this case the and get those to print to a text file.

My question is once I’ve got all the text in the extracted, what can I do with it? I am having trouble figuring out a way to isolate a particular word and further trim the text down to only what I need.

Here is what I have so far:

import urllib2
from BeautifulSoup import BeautifulSoup

url = 'http://www.website.com'
page = urllib2.urlopen(url)
soup = BeautifulSoup(page.read())

page = soup.findAll('title')

for element in page:    
    print element

file_name = raw_input("What do you want to name the file?> ")
text_file = open("/Users/user1/Projects/%s.txt" % file_name, "w")
text_file.write("%s" % page)
text_file.close()   

What gets returned to me is:

$<title>food</title>
<title>ball</title>
<title>car</title>
<title>desk</title>
<title>blue food</title>
<title>green food</title>
<title>red ball</title>

How would I get it to only print results that include ‘food’?

  • 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-01T07:54:39+00:00Added an answer on June 1, 2026 at 7:54 am

    You can get the contents of an element using .string. If you only wish to include results with food, add a check for that:

    for element in page:
        if 'food' in element.string:
            print element.string
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, I have this between my head tags <script type=text/javascript> hidden_links = document.getElementsByName(javascript_needed); for
Overall goal: User enters some number in minutes and I change those numbers from
The overall goal here is to have jetty be configured with a client certificate
My overall goal is to be able to create a pixel shader that takes
I have a web form that ask a user for their Id. My overall
Overall goal of my project is to connect to a Oracle database that is
The overall goal I'm trying to accomplish is to implement a customizable avatar system
Are there overall rules/guidelines for what makes a method thread-safe? I understand that there
I'm going to assume that the overall structure of my code as it currently
I'm making a program with the Pygame that changes the overall colours of inserted

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.