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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:18:17+00:00 2026-06-16T19:18:17+00:00

I am using beautiful soup to scrape some data from a website but I

  • 0

I am using beautiful soup to scrape some data from a website but I am not able to remove html tags from the data while printing it. Referred code is:

import csv
import urllib2
import sys  
from bs4 import BeautifulSoup

page = urllib2.urlopen('http://www.att.com/shop/wireless/devices/smartphones.html').read()
soup = BeautifulSoup(page)
soup.prettify()
for anchor1 in soup.findAll('div', {"class": "listGrid-price"}):
    print anchor1
for anchor2 in soup.findAll('div', {"class": "gridPrice"}):
    print anchor2
for anchor3 in soup.findAll('div', {"class": "gridMultiDevicePrice"}):
    print anchor3

Output which I am getting using this, looks like this:

<div class="listGrid-price"> 
                                $99.99 
            </div>
<div class="listGrid-price"> 
                                $0.01 
            </div>
<div class="listGrid-price"> 
                                $0.01 
            </div>

I want only prices in output without having any html tags around it. Pardon me for my ignorance as I am new to programming.

  • 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-16T19:18:20+00:00Added an answer on June 16, 2026 at 7:18 pm

    You are printing the found tag. To only print the contained text, use the .string attribute:

    print anchor1.string
    

    The .string value is a NavigableString instance; to use it like a normal unicode object, convert it first. Then you could use strip() to remove the extra whitespace:

    print unicode(anchor1.string).strip()
    

    Adjusting this a little to allow for empty values:

    for anchor1 in soup.findAll('div', {"class": "listGrid-price"}):
        if anchor1.string:
            print unicode(anchor1.string).strip()
    

    which gives me:

    $99.99
    $0.99
    $0.99
    $299.99
    $199.99
    $49.99
    $49.99
    $99.99
    $0.99
    $99.99
    $0.01
    $0.01
    $0.01
    $0.01
    $0.01
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Mechanize and Beautiful soup to scrape some data off Delicious from mechanize
I am using combination of PyQt and beautiful soup to scrape data from a
I am using Beautiful Soup to extract 'content' from web pages. I know some
I'm trying to scrape some data off of the FEC.gov website using python for
I have this code that fetches some text from a page using BeautifulSoup soup=
I'm using Beautiful Soup, but couldn't figure out how to do it. </td> <td
I am trying to scrape form field IDs using Beautiful Soup like this for
I'm using Beautiful Soup for extracting some texts. The program works on the command
I am using Beautiful Soup to pull out specific div tags, and it seems
I am using below reffered code to scrape some item names from a site:

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.