1

from mechanize import Browser br = Browser() page = br.open(' http://wow.interzet.ru/news.php?readmore=23 ') br.form = br.forms().next() print br .form 给我以下错误:

Traceback (most recent call last):
  File "C:\Users\roddik\Desktop\mech.py", line 6, in <module>
    br.form = br.forms().next()
  File "build\bdist.win32\egg\mechanize\_mechanize.py", line 426, in forms
  File "D:\py26\lib\site-package\mechanize-0.1.11-py2.6.egg\mechanize\_html.py", line 559, in forms
  File "D:\py26\lib\site-packages\mechanize-0.1.11-py2.6.egg\mechanize\_html.py", line 225, in forms
  File "D:\py26\lib\site-packages\clientform-0.2.10-py2.6.egg\ClientForm.py", line 967, in ParseResponseEx
  File "D:\py26\lib\site-packages\clientform-0.2.10-py2.6.egg\ClientForm.py", line 1100, in _ParseFileEx
  File "D:\py26\lib\site-packages\clientform-0.2.10-py2.6.egg\ClientForm.py", line 870, in feed
  File "D:\py26\lib\sgmllib.py", line 104, in feed
    self.goahead(0)
  File "D:\py26\lib\sgmllib.py", line 138, in goahead
    k = self.parse_starttag(i)
  File "D:\py26\lib\sgmllib.py", line 290, in parse_starttag
    self._convert_ref, attrvalue)
  File "D:\py26\lib\sgmllib.py", line 302, in _convert_ref
    return self.convert_charref(match.group(2)) or \
  File "D:\py26\lib\site-packages\clientform-0.2.10-py2.6.egg\ClientForm.py", line 850, in convert_charref
  File "D:\py26\lib\site-packages\clientform-0.2.10-py2.6.egg\ClientForm.py", line 244, in unescape_charref

ValueError: invalid literal for int() with base 10: 'e'

我该如何解决?

编辑:

我已经这样修好了。可以吗?如果不是,如何取而代之?

import ClientForm
from mechanize import Browser

def myunescape_charref(data, encoding):
    if not str(data).isdigit(): return 0
    name, base = data, 10
    if name.startswith("x"):
        name, base= name[1:], 16
    uc = unichr(int(name, base))
    if encoding is None:
        return uc
    else:
        try:
            repl = uc.encode(encoding)
        except UnicodeError:
            repl = "&#%s;" % data
        return repl

ClientForm.unescape_charref = myunescape_charref
4

1 回答 1

1

问题是由这样的网址引起的

http://wow.zet/forum/index.php?showtopic=1197&pid=30419&st=0&#entry30419

ClientForm 在 之后寻找一个整数

可以在 url 中使用 #,但它应该在 html 中转义,因为 表示字符编码

于 2009-10-05T21:06:26.330 回答