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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T14:41:31+00:00 2026-05-17T14:41:31+00:00

I am more than a bit tired, but here goes: I am doing tome

  • 0

I am more than a bit tired, but here goes:

I am doing tome HTML scraping in python 2.6.5 with BeautifulSoap on an ubuntubox

Reason for python 2.6.5: BeautifulSoap sucks under 3.1

I try to run the following code:

# dataretriveal from html files from DETHERM
# -*- coding: utf-8 -*-

import sys,os,re,csv
from BeautifulSoup import BeautifulSoup


sys.path.insert(0, os.getcwd())

raw_data = open('download.php.html','r')
soup = BeautifulSoup(raw_data)

for numdiv in soup.findAll('div', {"id" : "sec"}):
    currenttable = numdiv.find('table',{"class" : "data"})
    if currenttable:
        numrow=0
        numcol=0
        data_list=[]
        for row in currenttable.findAll('td', {"class" : "dataHead"}):
            numrow=numrow+1
        for ncol in currenttable.findAll('th', {"class" : "dataHead"}):
            numcol=numcol+1
        for col in currenttable.findAll('td'):
            col2 = ''.join(col.findAll(text=True))
        if col2.index('±'):
        col2=col2[:col2.index('±')]
            print(col2.encode("utf-8"))
        ref=numdiv.find('a')
        niceref=''.join(ref.findAll(text=True))

Now due to the ± signs i get the following error when trying to interprent the code with:

python code.py

Traceback (most recent call last):
File “detherm-wtest.py”, line 25, in
if col2.index(‘±’):
UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xc2 in position 0: ordinal not in range(128)

How do i solve this? putting an u in so we have: ‘±’ -> u’±’ results in:

Traceback (most recent call last):
File “detherm-wtest.py”, line 25, in
if col2.index(u’±’):
ValueError: substring not found

current code file encoding is utf-8

thank you

  • 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-17T14:41:31+00:00Added an answer on May 17, 2026 at 2:41 pm

    Byte strings like "±" (in Python 2.x) are encoded in the source file’s encoding, which might not be what you want. If col2 is really a Unicode object, you should use u"±" instead like you already tried. You might know that somestring.index raises an exception if it doesn’t find an occurrence whereas somestring.find returns -1. Therefore, this

        if col2.index('±'):
            col2=col2[:col2.index('±')] # this is not indented correctly in the question BTW
            print(col2.encode("utf-8"))
    

    should be

        if u'±' in col2:
            col2=col2[:col2.index(u'±')]
            print(col2.encode("utf-8"))
    

    so that the if statement doesn’t lead to an exception.

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

Sidebar

Related Questions

I have following html markup, bit more than demo here with mixture of li/ul
Double has range more than a 64-bit integer, but its precision is less dues
Essentially I want to replicate li:hover+li but it's a bit more complicated than that.
I know that a 32-bit OS cannot see more than 4 GB of RAM.
My problem is a bit more complex than using the following simple JavaScript code:
It's actually a bit more complicated than the title. I'm trying to figure out
Using virtualenvwrapper to develop on the CKAN project is a bit more complex than
I'm trying to learn a little bit more about recursion but somehow I can't
This is a bit more tricky than it sounds so let me try my
I'm asking for something that's a bit weird, but here is my requirement (which

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.