我正在使用Twill和Python编写网络爬网。 showforms()返回

Form name=customRatesForm (#1)
## ## __Name__________________ __Type___ __ID________ __Value__________________
10    originState              hidden    originState  TN 
11    destState                hidden    destState    IL 
12    originZip                text      originZip    37130 
13    destZip                  text      destZip      60602 
16    classes                  select    classes1     ['0000'] of ['0000', '0500', '0550', ... 
17    weight                   text      weight1      600 
18    weight                   text      weight2       
19    weight                   text      weight3       
20    weight                   text      weight4       
30 1  submit                   submi ... submit      

我已经取出了大部分行,以使其更容易阅读。我的问题是实际上有12个选择,所有这些都有名称为“类”。这些通过CGI作为列表。但是,Twill似乎无法区分它们。另外,当我跑步时

fv('1', 'classes', '0500')

我收到以下错误:

_mechanize_dist.ClientForm.AmbiguityError: id=None name='0500' label=None

我已经尝试了一些解决方法,包括将选择命名为ID,然后重写提交功能以使用jQuery选择器并重新分配其“名称”属性回到“类”:

$('.myclasses').attr('name', 'classes');

当我在浏览器中查看此内容时,它似乎可以按预期重新分配它们。但是,Twill的标题仍然显示为提交名称“ class1”,“ class2”,等。

任何帮助将非常感激。我不知道的解决方法。因为这不是我的页面,所以我受其控制器对“类”选择列表的期望的约束。

有帮助吗?

解决方案

据我所知,到目前为止,无法使用Twill做到这一点。任何解决方案都将是Twill以外的解决方法。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top