2010-10-31 5 views
1

Je reçois cette erreur:Python/Mechanize - Impossible de sélectionner la forme - ParseError (exc)

>>> br = Browser() 
>>> br.open("http://www.bestforumz.com/forum/") 
<response_seek_wrapper at 0x21f9fd0 
whose wrapped object = 
<closeable_response at 0x21f9558 whose 
fp = <socket._fileobject object at 
0x021F5F30>>> 
>>> br.select_form(nr=0) 

Traceback (most recent call last): 
    File "<pyshell#3>", line 1, in <module> 
    br.select_form(nr=0) 
    File "build\bdist.win32\egg\mechanize\_mechanize.py", line 505, in select_form 
    global_form = self._factory.global_form 
    File "build\bdist.win32\egg\mechanize\_html.py", line 546, in __getattr__ 
    self.forms() 
    File "build\bdist.win32\egg\mechanize\_html.py", line 559, in forms 
    self._forms_factory.forms()) 
    File "build\bdist.win32\egg\mechanize\_html.py", line 228, in forms 
    raise ParseError(exc) 
ParseError: <unprintable ParseError object> 

S'il vous plaît me HEP sur

Merci

Répondre

1

mécaniser n'est pas garanti pour analyser tous HTML Vous pourriez avoir à le faire à la main (ce qui n'est pas trop dur, c'est Python).

Souhaitez-vous publier une requête sur la page search.php du site? Vous pouvez utiliser urllib2 pour cela.

import urllib2 
import urllib 

values = dict(foo="hello", bar="world") # examine form for actual vars 
try: 
    req = urllib2.Request("http://example.com/search.php", 
          urllib.urlencode(values)) 
    response_page = urllib2.urlopen(req).read() 
except urllib2.HTTPError, details: 
    pass #do something with the error here... 
3

Je vous dis cela est un secret que j'ai été utilisé pour html parse (le but est de faire une analyse syntaxique html par la force mécaniser)

br = mechanize.Browser(factory=mechanize.DefaultFactory(i_want_broken_xhtml_support=True)) 
Questions connexes