如果/ Else语句不是在尝试获取地址列表时

时间:2014-07-27 08:54:13

标签: autohotkey

我正在尝试在以下网址上运行if / else语句:

http://nominatim.openstreetmap.org/search.php?q=MK3+5JE&viewbox=-147.13%2C72.78%2C147.13%2C-55.67

http://nominatim.openstreetmap.org/search.php?q=MK1+1AS&viewbox=-147.13%2C72.78%2C147.13%2C-55.67

我的代码如下:

; Collect results 1
Sleep 1000
Addr1 := IE.document.getElementsByClassName("name")[0].innerHTML
If Substr(Addr1, 1, 2) = "MK"
    {
    StringSplit, AddrNew, Addr1, `,
    StringTrimLeft, AddrNew3, AddrNew3, 1 
    Addr1 := AddrNew2 . "," . AddrNew3 . "," . PostCode
    MsgBox, %Addr1%
    }
Else If Substr(Addr1, 1, 2) <> "MK"
    {
    StringSplit, AddrNew, Addr1, `,
    StringTrimLeft, AddrNew2, AddrNew2, 1 
    Addr1 := AddrNew1 . "," . AddrNew2 . "," . PostCode
    MsgBox, %Addr1%
    }

; Collect results 2
Sleep 1000
Addr := IE.document.getElementsByClassName("name")[2].innerHTML
If Substr(Addr, 1, 2) = "MK"
    {
    StringSplit, AddrNew, Addr2, `,
    StringTrimLeft, AddrNew3, AddrNew3, 1 
    Addr := AddrNew2 . "," . AddrNew3 . "," . PostCode
    MsgBox, %Addr%
    }
Else If Substr(Addr, 1, 2) <> "MK"
    {
    StringSplit, AddrNew, Addr2, `,
    StringTrimLeft, AddrNew2, AddrNew2, 1 
    Addr := AddrNew1 . "," . AddrNew2 . "," . PostCode
    MsgBox, %Addr%
    }

每次尝试抓取数据时,都会发生以下情况:

enter image description here

enter image description here

enter image description here

enter image description here

正确的输出应

  1. Saint Andrew's Road,Far Bletchley

  2. Buckingham Road,Far Bletchley

  3. Mount Farm,Milton Keynes

  4. 道森农场道森路

  5. 知道是什么导致了这个问题吗?

1 个答案:

答案 0 :(得分:0)

想出来 - 我没有跟踪我的变量......

    ; Collect results 1
    Sleep 1000
    Addr1 := IE.document.getElementsByClassName("name")[0].innertext
    String_Object := StrSplit(addr1, "`,")
    If (Substr(Addr1, 1, 2) = "MK")
    {
        Addr1 := String_Object[2] . "," . Trim(String_Object[3]) . "," . PostCode
        MsgBox, %Addr1%
    }
    Else
    {
        Addr1 := String_Object[1] . "," . Trim(String_Object[2]) . "," . PostCode
        MsgBox, %Addr1%
    }

    ; Collect results 2
    Sleep 1000
    Addr2 := IE.document.getElementsByClassName("name")[1].innertext
    String_Object := StrSplit(addr2, "`,")
    If (Substr(Addr2, 1, 2) = "MK")
    {
        Addr2 := String_Object[2] . "," . Trim(String_Object[3]) . "," . PostCode
        MsgBox, %Addr2%
    }
    Else
    {
        Addr2 := String_Object[1] . "," . Trim(String_Object[2]) . "," . PostCode
        MsgBox, %Addr2%
    }