gpt4 book ai didi

python - 这个错误是什么意思 : ValueError: unknown POST form encoding type ' ' (and how to solve it? )

转载 作者:行者123 更新时间:2023-12-04 16:22:24 54 4
gpt4 key购买 nike

我正在尝试使用 mechanize 抓取网站( http://www.dataescolabrasil.inep.gov.br/dataEscolaBrasil/home.seam )但我收到一个我无法理解的错误(因此无法解决)。这可能是由于我对 Web 开发的了解不足。

这是我想要做的:

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()

这是我得到的运行时错误:
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,但没有成功。

最佳答案

我从您的示例中找到了页面上的表单:

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

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

关于python - 这个错误是什么意思 : ValueError: unknown POST form encoding type ' ' (and how to solve it? ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15092462/

54 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com