机械化:首先形式工作,然后“未知的GET表单编码类型”utf-8“ [英] mechanize: first form works, then "unknown GET form encoding type 'utf-8'"

查看:173
本文介绍了机械化:首先形式工作,然后“未知的GET表单编码类型”utf-8“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从EUR-Lex网站填写2份表格,以便从生成的网页上记录一些数据。
我被困在表格#2。我感觉这应该很简单,我已经研究了一点,但没有运气。

I am trying to fill out 2 forms from the EUR-Lex website in order to record some data from the generated webpage. I am stuck at form #2. I get the feeling this should be easy and I've researched a bit, but no luck.

import mechanize

froot = '...'
f = open(froot + 'text.html', 'w')

br = mechanize.Browser()
br.open('http://eur-lex.europa.eu/RECH_legislation.do')
br.select_form(name='form2')
br['T1'] = ['V112']
br['T3'] = ['V2']
br['T2'] = ['V1']

first_page = br.submit()
f.write(first_page.get_data())

直到这里似乎都有效,因为我得到保存到文件的正确页面的源。但是...然后...

up until here everything seems to work, because I get the source of the correct page saved to the file. But then...

br.select_form(name='form2')
br['typedate'] = ['PD']

br['startaaaa'] = '1960'
br['startmm'] = '01'
br['startjj'] = '01'
br['endaaaa'] = '1960'
br['endmm'] = '12'
br['startjj'] = '31'

next = br.submit()

这里一切都停止了:

ValueError: unknown GET form encoding type 'utf-8'

在选择第一个和第二个表单之前,我选中了 br.enctype 。我得到的是:

I checked br.enctype before selecting the first and second forms. What I get is:


  • 第一个表单后: application / x-www-form-urlencoded

  • 第二种形式: utf-8

  • after the first form: application/x-www-form-urlencoded
  • after the second form: utf-8

我不知道这里发生了什么。

I don't know what is going on here.

推荐答案

问题:

在更改源代码后,我重新安装了机械化

I re-installed mechanize after changing the source

第3233行 _form.py

if (self.enctype != "application/x-www-form-urlencoded") and (self.enctype != "utf-8"):

错了,只能处理我的情况。
,但在我的具体情况下它的工作。

it's probably very wrong and can only probably handle my case. but in my specific case it works.

这篇关于机械化:首先形式工作,然后“未知的GET表单编码类型”utf-8“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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