2015-05-29 9 views
6

Sto tentando di inviare un modulo su questo page utilizzando Mechanize.Codifica dei caratteri corretti della pagina Web con python Mechanize

br.open("http://mspc.bii.a-star.edu.sg/tankp/run_depth.html") 
#selecting form to fill 
br.select_form(nr = 0) 
#input for the form 
br['pdb_id'] = '1atp' 
req = br.submit() 

Ciò tuttavia pronunciato la seguente errore

mechanize._form.ParseError: expected name token at '<! INPUT PDB FILE>\n\t' 

immagino questo è causa di qualche personaggio codifica fuori luogo (ref). Vorrei sapere come risolvere questo problema.

risposta

2

Il tuo problema è un errore HTML comment tags, che porta a un sito Web non valido che il parser di mechanize non può leggere. Ma puoi invece usare il use the included BeautifulSoup parser (Python 2.7.9, mechanize 0.2.5):

#!/usr/bin/env python 
#-*- coding: utf-8 -*- 
import mechanize 

br = mechanize.Browser(factory=mechanize.RobustFactory()) 
br.open('http://mspc.bii.a-star.edu.sg/tankp/run_depth.html') 
br.select_form(nr=0) 
br['pdb_id'] = '1atp' 
response = br.submit()