开发者

Mechanize: Submit form with input type=image

开发者 https://www.devze.com 2023-04-03 11:08 出处:网络
Hi I\'m having trouble submitting an old asp.net webform that takes me to the \"next page\" in a search result. It looks like this

Hi I'm having trouble submitting an old asp.net webform that takes me to the "next page" in a search result. It looks like this

<!-- Der er flere biler -->
<form action="http:Autofund.asp?" method="POST">
<input type="hidden" name="Markevalg" value="0">
<input type="hidden" name="Modelvalg" value="">
<input type="hidden" name="TypeValg" value="">
<input type="hidden" name="ArtValg" value="0">
<input type="hidden" name="FarveValg" value="">
<input type="hidden" name="FraPris" value="">
<input type="hidden" name="TilPris" value="">
<input type="hidden" name="FraKm" value="">
<input type="hidden" name="TilKm" value="">
<input type="hidden" name="ArFra" value="">
<input type="hidden" name="ArTil" value="">
<input type="hidden" name="FV" value="">
<input type="hidden" name="HeleLandet" value="">
<input type="hidden" name="StorKbh" value="">
<input type="hidden" name="NordSj" value="">
<input type="hidden" name="SydSj" value="">
<input type="hidden" name="FynMV" value="">
<input type="hidden" name="SydJylland" value="">
<input type="hidden" name="MidtJylland" value="">
<input type="hidden" name="OstJylland" value="">
<input type="hidden" name="NordJylland" value="">
<input type="hidden" name="GemBilvalg" value="Alfa RomeoMiTo1,4 M-Air 170 Quadrifoglio3202699">
<input type="hidden" name="FuelId" value="0">
<input type="hidden" name="StartRecord" value="OFF">
<!-- Dette gøres for at kunne bladre videre til de næste 10 -->

<tr><td width="2"></td><td width="120"></td></tr>
</table>
<p align="center">
<center>
<font face="Arial">

    <!-- Der er flere biler --> 
    <input type="image" src="../images/flerbil.jpg" align="bottom" border="0" WIDTH="110" HEIGHT="40"> 

    <a href="#TOPSIDE"><img src="../images/tiltop.jpg" alt="Top side" align="bottom" border="0" WIDTH="110" HEIGHT="40"></a>
    <a href="../HelpSog1.htm"><img src="../images/help.jpg" alt="Hjælp" align="bottom" border="0" WIDTH="110" HEIGHT="40"></a>

    <!-- Der er flere biler -->  
    </form>

</font></p>

If I do like this:

agent.submit(page.forms.last)

I'm getting an error:

You have a nil object when you didn''t expect it! You might have expected an instance of Array. The error occurred while evaluating nil.length /Users/user/.rvm/gems/ruby-1.9.2-p180@webproject/gems/mechanize-2.0.1/lib/mechanize/http/agent.rb:408

I can see if i do a:

puts page.forms.last.inspect

That it is the right form that it selects, because it returns:

#<Mechanize::Form
 {name nil}
 {method "POST"}
 {action "http:Autofund.asp?"}
 {fields
  #<Mechanize::Form::Hidden:0x007fdcc2b0de60
   @name="Markevalg",
   @node=
    #(Element:0x3fee61587020 {
      name = "input",
      attributes = [
        #(Attr:0x3fee6158101c { name = "type", value = "hidden" }),
        #(Attr:0x3fee61581008 { name = "name", value = "Markevalg" }),
        #(Attr:0x3fee61580ff4 { name = "value", value = "" })]
      }),
   @value="">
  #<Mechanize::Form::Hidden:0x007fdcc2b0d2a8
   @name="Modelvalg",
   @node=
    #(Element:0x3fee61586a30 {
      name = "input",
      attributes = [
        #(Attr:0x3fee6157b888 { name = "type", value = "hidden" }),
        #(Attr:0x3fee6157b874 { name = "name", value = "Modelvalg" }),
        #(Attr:0x3fee6157b860 { name = "value", value = "" })]
      }),
   @value="">
  #<Mechanize::Form::Hidden:0x007fdcc2b0cd80
   @name="TypeValg",
   @node=
    #(Element:0x3fee61586788 {
      name = "input",
      attributes = [
        #(Attr:0x3fee61575910 { name = "type", value = "hidden" }),
        #(Attr:0x3fee615758e8 { name = "name", value = "TypeValg" }),
        #(Attr:0x3fee615758d4 { name = "value", value = "" })]
      }),
   @value="">
  #<Mechanize::Form::Hidden:0x007fdcc2b0c8f8
   @name="ArtValg",
   @node=
    #(Element:0x3fee615865bc {
      name = "input",
      attributes = [
        #(Attr:0x3fee61570ec4 { name = "type", value = "hidden" }),
        #(Attr:0x3fee61570e60 { name = "name", value = "ArtValg" }),
        #(Attr:0x3fee61570dac { name = "value", value = "8" })]
      }),
   @value="8">
  #<Mechanize::Form::Hidden:0x007fdcc2b0c330
   @name="FarveValg",
   @node=
    #(Element:0x3fee61586378 {
      name = "input",
      attributes = [
        #(Attr:0x3fee6156b884 { name = "type", value = "hidden" }),
        #(Attr:0x3fee6156b848 { name = "name", value = "FarveValg" }),
        #(Attr:0x3fee6156b834 { name = "value", value = "" })]
      }),
   @value="">
  #<Mechanize::Form::Hidden:0x007fdcc2b0bef8
   @name="FraPris",
   @node=
    #(Element:0x3fee6158606c {
      name = "input",
      attributes = [
        #(Attr:0x3fee615668c0 { name = "type", value = "hidden" }),
        #(Attr:0x3fee615668ac { name = "name", value = "FraPris" }),
        #(Attr:0x3fee61566898 { name = "value", value = "10000" })]
      }),
   @value="10000">
  #<Mechanize::Form::Hidden:0x007fdcc2b0bc50
   @name="TilPris",
   @node=
    #(Element:0x3fee61585ef0 {
      name = "input",
      attributes = [
        #(Attr:0x3fee61562f2c { name = "type", value = "hidden" }),
        #(Attr:0x3fee61562f18 { name = "name", value = "TilPris" }),
        #(Attr:0x3fee61562f04 { name = "value", value = "2000000" })]
      }),
   @value="2000000">
  #<Mechanize::Form::Hidden:0x007fdcc2b0b9f8
   @name="FraKm",
   @node=
    #(Element:0x3fee61585d9c {
      name = "input",
      attributes = [
        #(Attr:0x3fee6155ee54 { name = "type", value = "hidden" }),
        #(Attr:0x3fee6155ee40 { name = "name", value = "FraKm" }),
        #(Attr:0x3fee6155ee2c { name = "value", value = "0" })]
      }),
   @value="0">
  #<Mechanize::Form::Hidden:0x007fdcc2b0b638
   @name="TilKm",
   @node=
    #(Element:0x3fee61585be4 {
      name = "input",
      attributes = [
        #(Attr:0x3fee6155aed0 { name = "type", value = "hidden" }),
        #(Attr:0x3fee6155aebc { name = "name", value = "TilKm" }),
        #(Attr:0x3fee6155aea8 { name = "value", value = "500000" })]
      }),
   @value="500000">
  #<Mechanize::Form::Hidden:0x007fdcc2b0b368
   @name="ArFra",
   @node=
    #(Element:0x3fee61585a90 {
      name = "input",
      attributes = [
        #(Attr:0x3fee61557b68 { name = "type", value = "hidden" }),
        #(Attr:0x3fee61557b54 { name = "name", value = "ArFra" }),
        #(Attr:0x3fee61557b2c { name = "value", value = "1990" })]
      }),
   @value="1990">
  #<Mechanize::Form::Hidden:0x007fdcc2b0b048
   @name="ArTil",
   @node=
    #(Element:0x3fee615858d8 {
      name = "input",
      attributes = [
        #(Attr:0x3fee61554828 { name = "type", value = "hidden" }),
        #(Attr:0x3fee61554814 { name = "name", value = "ArTil" }),
        #(Attr:0x3fee61554800 { name = "value", value = "2012" })]
      }),
   @value="2012">
  #<Mechanize::Form::Hidden:0x007fdcc2b0ac88
   @name="FV",
   @node=
    #(Element:0x3fee61585748 {
      name = "input",
      attributes = [
        #(Attr:0x3fee6155172c { name = "type", value = "hidden" }),
        #(Attr:0x3fee61551704 { name = "name", value = "FV" }),
        #(Attr:0x3fee615516f0 { name = "value", value = "" })]
      }),
   @value="">
  #<Mechanize::Form::Hidden:0x007fdcc2b0a850
   @name="HeleLandet",
   @node=
    #(Element:0x3fee61585568 {
      name = "input",
      attributes = [
        #(Attr:0x3fee6154e108 { name = "type", value = "hidden" }),
        #(Attr:0x3fee6154e0b8 { name = "name", value = "HeleLandet" }),
        #(Attr:0x3fee6154e0a4 { name = "value", value = "" })]
      }),
   @value="">
  #<Mechanize::Form::Hidden:0x007fdcc2b0a530
   @name="StorKbh",
   @node=
    #(Element:0x3fee61585374 {
      name = "input",
      attributes = [
        #(Attr:0x3fee6154adb4 { name = "type", value = "hidden" }),
        #(Attr:0x3fee6154ada0 { name = "name", value = "StorKbh" }),
        #(Attr:0x3fee6154ad8c { name = "value", value = "" })]
      }),
   @value="">
  #<Mechanize::Form::Hidden:0x007fdcc2b0a170
   @name="NordSj",
   @node=
    #(Element:0x3fee615851a8 {
      name = "input",
      attributes = [
        #(Attr:0x3fee615479ac { name = "type", value = "hidden" }),
        #(Attr:0x3fee61547998 { name = "name", value = "NordSj" }),
        #(Attr:0x3fee61547984 { name = "value", value = "" })]
      }),
   @value="">
  #<Mechanize::Form::Hidden:0x007fdcc2b09b08
   @name="SydSj",
   @node=
    #(Element:0x3fee61584eb0 {
      name = "input",
      attributes = [
        #(Attr:0x3fee61544978 { name = "type", value = "hidden" }),
        #(Attr:0x3fee61544964 { name = "name", value = "SydSj" }),
        #(Attr:0x3fee61544950 { name = "value", value = "" })]
      }),
   @value="">
  #<Mechanize::Form::Hidden:0x007fdcc2b097e8
   @name="FynMV",
   @node=
    #(Element:0x3fee61584c94 {
      name = "input",
      attributes = [
        #(Attr:0x3fee61540ee0 { name = "type", value = "hidden" }),
        #(Attr:0x3fee61540eb8 { name = "name", value = "FynMV" }),
        #(Attr:0x3fee61540ea4 { name = "value", value = "" })]
      }),
   @value="">
  #<Mechanize::Form::Hidden:0x007fdcc2b094c8
   @name="SydJylland",
   @node=
    #(Element:0x3fee61584b18 {
      name = "input",
      attributes = [
        #(Attr:0x3fee6153bf6c { name = "ty开发者_运维问答pe", value = "hidden" }),
        #(Attr:0x3fee6153bf58 { name = "name", value = "SydJylland" }),
        #(Attr:0x3fee6153bf44 { name = "value", value = "" })]
      }),
   @value="">
  #<Mechanize::Form::Hidden:0x007fdcc2b09068
   @name="MidtJylland",
   @node=
    #(Element:0x3fee615849b0 {
      name = "input",
      attributes = [
        #(Attr:0x3fee61538ee8 { name = "type", value = "hidden" }),
        #(Attr:0x3fee61538ed4 { name = "name", value = "MidtJylland" }),
        #(Attr:0x3fee61538ec0 { name = "value", value = "" })]
      }),
   @value="">
  #<Mechanize::Form::Hidden:0x007fdcc2b08ca8
   @name="OstJylland",
   @node=
    #(Element:0x3fee6158476c {
      name = "input",
      attributes = [
        #(Attr:0x3fee6152bff4 { name = "type", value = "hidden" }),
        #(Attr:0x3fee6152bfe0 { name = "name", value = "OstJylland" }),
        #(Attr:0x3fee6152bfcc { name = "value", value = "" })]
      }),
   @value="">
  #<Mechanize::Form::Hidden:0x007fdcc2b089d8
   @name="NordJylland",
   @node=
    #(Element:0x3fee615845a0 {
      name = "input",
      attributes = [
        #(Attr:0x3fee61526a54 { name = "type", value = "hidden" }),
        #(Attr:0x3fee61526a40 { name = "name", value = "NordJylland" }),
        #(Attr:0x3fee61526a18 { name = "value", value = "" })]
      }),
   @value="">
  #<Mechanize::Form::Hidden:0x007fdcc2b08780
   @name="GemBilvalg",
   @node=
    #(Element:0x3fee61584460 {
      name = "input",
      attributes = [
        #(Attr:0x3fee6151ed7c { name = "type", value = "hidden" }),
        #(Attr:0x3fee6151ed68 { name = "name", value = "GemBilvalg" }),
        #(Attr:0x3fee6151ed54 {
          name = "value",
          value = "MitsubishiGrandis2,4 Intense 165HK3180120"
          })]
      }),
   @value="MitsubishiGrandis2,4 Intense 165HK3180120">
  #<Mechanize::Form::Hidden:0x007fdcc2b084b0
   @name="FuelId",
   @node=
    #(Element:0x3fee6158430c {
      name = "input",
      attributes = [
        #(Attr:0x3fee6151b208 { name = "type", value = "hidden" }),
        #(Attr:0x3fee6151b1cc { name = "name", value = "FuelId" }),
        #(Attr:0x3fee6151b1b8 { name = "value", value = "1" })]
      }),
   @value="1">
  #<Mechanize::Form::Hidden:0x007fdcc2b08230
   @name="StartRecord",
   @node=
    #(Element:0x3fee615841cc {
      name = "input",
      attributes = [
        #(Attr:0x3fee615165c8 { name = "type", value = "hidden" }),
        #(Attr:0x3fee615165b4 { name = "name", value = "StartRecord" }),
        #(Attr:0x3fee615165a0 { name = "value", value = "OFF" })]
      }),
   @value="OFF">}
 {radiobuttons}
 {checkboxes}
 {file_uploads}
 {buttons}>
0

精彩评论

暂无评论...
验证码 换一张
取 消