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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:08:16+00:00 2026-06-10T07:08:16+00:00

I’m scraping a website with Python 2.7 using BeautifulSoup. Here’s my code: # -*-

  • 0

I’m scraping a website with Python 2.7 using BeautifulSoup. Here’s my code:

# -*- coding: utf-8 -*-

from BeautifulSoup import BeautifulSoup
import urllib
import json

url = 'http://www.website.com'
file_pointer = urllib.urlopen(url)
html_object = BeautifulSoup(file_pointer)

type_select = html_object('select',{'id':'which'})

for option in type_select:
    value = option('option')
    for type_value in value:
        type =  type_value.contents[0]
        param_1 = type_value['value']
        print 'Type:', type

        url2 = 'http://www/website.com/' + param_1
        file_pointer2 = urllib.urlopen(url2)
        html_object2 = BeautifulSoup(file_pointer2)
        result = json.loads(str(html_object2))

        for json1 in result['DATA']:
            category = json1[0].title()
            param_2 = json1[0]
            print '   Category:', category

            url3 = 'http://www/website.com/' + param_2 + '&which=' + param_1
            file_pointer3 = urllib.urlopen(url3)
            html_object3 = BeautifulSoup(file_pointer3)
            result2 = json.loads(str(html_object3))

            for json2 in result2['DATA']:
                sub_category = json2[0]
                param_3 = sub_category.replace(' ','+').replace('&','%26')
                print '       sub_category:', sub_category

                for i in param_3:
                    if i == 'â':
                        print i
  ...

I need to replace the 'â' character for a fourth URL request to continue my scrape, but no matter what I try to replace (u'\u2019', â, etc.), I get a UnicodeEncodeError.

I tried converting param_3 to a string (because it is a BeautifulSoup Navigable String datatype) and replacing, but I get the same error, except on my str(param_3) line. I finally tried this for-loop comparison and get the warning:

UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
if i == 'â':

I’m at a loss here. How can I translate this character and replace it with other characters in param_3?

Any help is appreciated! Thanks in advance!

  • 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-10T07:08:18+00:00Added an answer on June 10, 2026 at 7:08 am

    BeautifulSoup returns Unicode strings, so use Unicode strings when operating on them. Also check out urllib.quote_plus. It looks like it does the replacements you want. You’ll need to .encode the Unicode string before using it with quote_plus.

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.