该错误是什么意思:ValueError:未知的POST表单编码类型“"(以及如何解决?) [英] What does this error mean: ValueError: unknown POST form encoding type ' ' (and how to solve it?)

查看:152
本文介绍了该错误是什么意思:ValueError:未知的POST表单编码类型“"(以及如何解决?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试抓取网站( http://www.dataescolabrasil .inep.gov.br/dataEscolaBrasil/home.seam ),但出现了我无法理解的错误(因此无法解决).那可能是由于我对Web开发的了解不足.

I'm trying to crawl a website (http://www.dataescolabrasil.inep.gov.br/dataEscolaBrasil/home.seam) using mechanize but I am getting an error I cannot understand (and therefore cannot solve). That's probably due to my poor knowledge of web development.

这就是我想要做的:

import mechanize

# this is the website I want to crawl
LINK = "http://www.dataescolabrasil.inep.gov.br/dataEscolaBrasil/home.seam"

br = mechanize.Browser()
br.open(LINK) 
request  = mechanize.Request(LINK)
response = mechanize.urlopen(request)

# there're two forms in the page (output ommited), I want the second one.
forms = mechanize.ParseResponse(response, backwards_compat=False)
for form in br.forms():
    print "Form name:", form.name
    print form

br.select_form(nr=1)
br.form['codEntidadeDecorate:codEntidadeInput'] = '11024968'
response2 = br.submit()

这是我遇到的运行时错误:

And here's the runtime error I'm getting:

Traceback (most recent call last):
  File "C:\test.py", line 19, in <module>
    response2 = br.submit()
  File "build\bdist.win32\egg\mechanize\_mechanize.py", line 541, in submit
  File "build\bdist.win32\egg\mechanize\_mechanize.py", line 530, in click
  File "build\bdist.win32\egg\mechanize\_form.py", line 2999, in click
  File "build\bdist.win32\egg\mechanize\_form.py", line 3201, in _click
  File "build\bdist.win32\egg\mechanize\_form.py", line 2350, in _click
  File "build\bdist.win32\egg\mechanize\_form.py", line 3269, in _switch_click
  File "build\bdist.win32\egg\mechanize\_form.py", line 3257, in _request_data
ValueError: unknown POST form encoding type ''

我尝试对传递给表单的字符串进行编码的一些调整,试图理解GET v.POST,但没有成功.

I've tried some tweaks to the of encoding the string I pass to the form, tried to understand GET v. POST, but no success.

推荐答案

我在您的示例页面上找到了该表单:

I found that form at page from your example:

<form id="buscaForm" name="buscaForm" method="post" action="/dataEscolaBrasil/home.seam;jsessionid=EFB3D6270E69EAE71733137219C3026B" enctype="">

我认为这是个问题, enctype 属性为空.您需要将此属性的值设置为 application/x-www-form-urlencoded 或将其删除以使用默认值.

I think it's a problem, empty enctype attribute. You need to set value of this attribute to application/x-www-form-urlencoded or remove it for use default.

这篇关于该错误是什么意思:ValueError:未知的POST表单编码类型“"(以及如何解决?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆