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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:36:13+00:00 2026-05-18T04:36:13+00:00

I’m parsing a web page written in spanish with scrapy . The problem is

  • 0

I’m parsing a web page written in spanish with scrapy. The problem is that I can’t save the text because of the wrong encoding.

This is the parse function:

def parse(self, response):
        hxs = HtmlXPathSelector(response)
        text = hxs.select('//text()').extract() # Ex: [u' Sustancia mineral, m\xe1s o menos dura y compacta, que no es terrosa ni de aspecto met\xe1lico.']
        s = "".join(text)
        db = dbf.Dbf("test.dbf", new=True)
        db.addField(
            ("WORD", "C", 25),
            ("DATA", "M", 15000), # Memo field
        )
        rec = db.newRecord()
        rec["WORD"] = "Stone"
        rec["DATA"] = s
        rec.store()
        db.close()

When I try to save it to a db(a dbf db) I get an ASCII(128) error. I tried decoding/encoding using ‘utf-8’ and ‘latin1’ but with no success.

Edit:

To save the db I’m using dbfpy. I added the dbf saving code in the parse function above.

This is the error message:

Traceback (most recent call last):
  File "/usr/lib/python2.6/dist-packages/twisted/internet/base.py", line 1179, in mainLoop
    self.runUntilCurrent()
  File "/usr/lib/python2.6/dist-packages/twisted/internet/base.py", line 778, in runUntilCurrent
    call.func(*call.args, **call.kw)
  File "/usr/lib/python2.6/dist-packages/twisted/internet/defer.py", line 280, in callback
    self._startRunCallbacks(result)
  File "/usr/lib/python2.6/dist-packages/twisted/internet/defer.py", line 354, in _startRunCallbacks
    self._runCallbacks()
--- <exception caught here> ---
  File "/usr/lib/python2.6/dist-packages/twisted/internet/defer.py", line 371, in _runCallbacks
    self.result = callback(self.result, *args, **kw)
  File "/home/katy/Dropbox/proyectos/rae/rae/spiders/rae_spider.py", line 54, in parse
    rec.store()
  File "/home/katy/Dropbox/proyectos/rae/rae/spiders/record.py", line 211, in store
    self.dbf.append(self)
  File "/home/katy/Dropbox/proyectos/rae/rae/spiders/dbf.py", line 214, in append
    record._write()
  File "/home/katy/Dropbox/proyectos/rae/rae/spiders/record.py", line 173, in _write
    self.dbf.stream.write(self.toString())
  File "/home/katy/Dropbox/proyectos/rae/rae/spiders/record.py", line 223, in toString
    for (_def, _dat) in izip(self.dbf.header.fields, self.fieldData)
  File "/home/katy/Dropbox/proyectos/rae/rae/spiders/fields.py", line 215, in encodeValue
    return str(value)[:self.length].ljust(self.length)
exceptions.UnicodeEncodeError: 'ascii' codec can't encode character u'\xf1' in position 18: ordinal not in range(128)
  • 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-18T04:36:14+00:00Added an answer on May 18, 2026 at 4:36 am

    Please, don’t remember that DBF files don’t support unicode at all
    and I also suggest to use Ethan Furman’s dbf package (link in another answer)

    You can use only ‘table = dbf.Table(‘filename’) to guess real type.

    Example of usage with non cp437 encoding is:

    #!/usr/bin/env python
    # coding: koi8-r
    import dbf
    text = 'текст в koi8-r'
    table = dbf.Table(':memory:', ['test M'], 128, False, False, True, False, 'dbf', 'koi8-r')
    record = table.append()
    record.test = text
    

    Please note following information about version 0.87.14 and ‘dbf’ table type:


    With DBF package 0.87.14 you can found exception ‘TypeError: ord() excepted character…’ at “…/site-packages/dbf/tables.py”, line 686

    Only ‘dbf’ table type has affected with this tupo!

    DISCLAIMER: I don’t know real correct values to use in following values, so don’t blame me about incompatibility with this “fix”.

    You can to replace values ” to ‘\0’ (at least) at lines 490 and 491 to make this test workable.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace

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.