diff options
author | Leonard Richardson <leonardr@segfault.org> | 2013-05-14 08:39:16 -0400 |
---|---|---|
committer | Leonard Richardson <leonardr@segfault.org> | 2013-05-14 08:39:16 -0400 |
commit | cab4e1708d6706d16ff31b25b2aef26e6ca15136 (patch) | |
tree | 98bb36921345f7f7f68770e959fca99f63a6fa51 /doc | |
parent | 9821fdc79d4dd8e7935ae76c75d8236bbb418300 (diff) | |
download | beautifulsoup4-cab4e1708d6706d16ff31b25b2aef26e6ca15136.tar.gz |
Added a deprecation warning to has_key().
Diffstat (limited to 'doc')
-rw-r--r-- | doc/source/conf.py | 2 | ||||
-rw-r--r-- | doc/source/index.rst | 30 |
2 files changed, 24 insertions, 8 deletions
diff --git a/doc/source/conf.py b/doc/source/conf.py index 56c0939..102c3cf 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -50,7 +50,7 @@ copyright = u'2012, Leonard Richardson' # The short X.Y version. version = '4' # The full version, including alpha/beta/rc tags. -release = '4.0.0' +release = '4.2.0' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/doc/source/index.rst b/doc/source/index.rst index 8e0204b..b1cbd21 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -1095,7 +1095,7 @@ Here's a function that returns ``True`` if a tag defines the "class" attribute but doesn't define the "id" attribute:: def has_class_but_no_id(tag): - return tag.has_key('class') and not tag.has_key('id') + return tag.has_attr('class') and not tag.has_attr('id') Pass this function into ``find_all()`` and you'll pick up all the <p> tags:: @@ -2746,16 +2746,11 @@ Other parser problems preserve mixed-case or uppercase tags and attributes, you'll need to :ref:`parse the document as XML. <parsing-xml>` +.. _misc: Miscellaneous ------------- -* ``KeyError: [attr]`` - Caused by accessing ``tag['attr']`` when the - tag in question doesn't define the ``attr`` attribute. The most - common errors are ``KeyError: 'href'`` and ``KeyError: - 'class'``. Use ``tag.get('attr')`` if you're not sure ``attr`` is - defined, just as you would with a Python dictionary. - * ``UnicodeEncodeError: 'charmap' codec can't encode character u'\xfoo' in position bar`` (or just about any other ``UnicodeEncodeError``) - This is not a problem with Beautiful Soup. @@ -2768,6 +2763,27 @@ Miscellaneous solution is to explicitly encode the Unicode string into UTF-8 with ``u.encode("utf8")``. +* ``KeyError: [attr]`` - Caused by accessing ``tag['attr']`` when the + tag in question doesn't define the ``attr`` attribute. The most + common errors are ``KeyError: 'href'`` and ``KeyError: + 'class'``. Use ``tag.get('attr')`` if you're not sure ``attr`` is + defined, just as you would with a Python dictionary. + +* ``AttributeError: 'ResultSet' object has no attribute 'foo'`` - This + usually happens because you expected ``find_all()`` to return a + single tag or string. But ``find_all()`` returns a _list_ of tags + and strings--a ``ResultSet`` object. You need to iterate over the + list and look at the ``.foo`` of each one. Or, if you really only + want one result, you need to use ``find()`` instead of + ``find_all()``. + +* ``AttributeError: 'NoneType' object has no attribute 'foo'`` - This + usually happens because you called ``find()`` and then tried to + access the `.foo`` attribute of the result. But in your case, + ``find()`` didn't find anything, so it returned ``None``, instead of + returning a tag or a string. You need to figure out why your + ``find()`` call isn't returning anything. + Improving Performance --------------------- |