首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用AHK脚本访问运行时生成的HTML

使用AHK脚本访问运行时生成的HTML
EN

Stack Overflow用户
提问于 2014-08-09 21:23:29
回答 1查看 122关注 0票数 1

如何访问在AHK上运行时生成的HTML?

在将邮政编码粘贴到搜索框(本网站- http://www.postcodeanywhere.co.uk/demos/address-finder/)后,我正在尝试访问下拉框的内容。

对于两个条目,网页代码如下:

代码语言:javascript
复制
 <div class="pca pcalist">
    <div class="pcaitem pcafirstitem pcaselected" title=
    "MK10 0AA, A C R Logistics, Standing Way, Brinklow, Milton Keynes">
        MK10 0AA, A C R Logistics, Standing Way, Brinklow, Milton Keynes
    </div>

    <div class="pcaitem pcalastitem" title=
    "MK10 0AA, Waitrose, A C R Logistics, Standing Way, Brinklow, Milton Keynes">
    MK10 0AA, Waitrose, A C R Logistics, Standing Way, Brinklow, Milton
    Keynes
    </div>
</div>

对于2+条目,网页代码如下:

代码语言:javascript
复制
<div class="pca pcalist">
    <div class="pcaitem pcafirstitem pcaselected" title=
    "MK13 7NA, 1, Bleasdale, Heelands, Milton Keynes">
        MK13 7NA, 1, Bleasdale, Heelands, Milton Keynes
    </div>


    <div class="pcaitem" title=
    "MK13 7NA, 2, Bleasdale, Heelands, Milton Keynes">
        MK13 7NA, 2, Bleasdale, Heelands, Milton Keynes
    </div>


    <div class="pcaitem" title=
    "MK13 7NA, 3, Bleasdale, Heelands, Milton Keynes">
        MK13 7NA, 3, Bleasdale, Heelands, Milton Keynes
    </div>


    <div class="pcaitem" title=
    "MK13 7NA, 4, Bleasdale, Heelands, Milton Keynes">
        MK13 7NA, 4, Bleasdale, Heelands, Milton Keynes
    </div>


    <div class="pcaitem" title=
    "MK13 7NA, 5, Bleasdale, Heelands, Milton Keynes">
        MK13 7NA, 5, Bleasdale, Heelands, Milton Keynes
    </div>


    <div class="pcaitem" title=
    "MK13 7NA, 6, Bleasdale, Heelands, Milton Keynes">
        MK13 7NA, 6, Bleasdale, Heelands, Milton Keynes
    </div>


    <div class="pcaitem" title=
    "MK13 7NA, 7, Bleasdale, Heelands, Milton Keynes">
        MK13 7NA, 7, Bleasdale, Heelands, Milton Keynes
    </div>


    <div class="pcaitem" title=
    "MK13 7NA, 8, Bleasdale, Heelands, Milton Keynes">
        MK13 7NA, 8, Bleasdale, Heelands, Milton Keynes
    </div>


    <div class="pcaitem" title=
    "MK13 7NA, 9, Bleasdale, Heelands, Milton Keynes">
        MK13 7NA, 9, Bleasdale, Heelands, Milton Keynes
    </div>


    <div class="pcaitem" title=
    "MK13 7NA, 10, Bleasdale, Heelands, Milton Keynes">
        MK13 7NA, 10, Bleasdale, Heelands, Milton Keynes
    </div>


    <div class="pcaitem" title=
    "MK13 7NA, 11, Bleasdale, Heelands, Milton Keynes">
        MK13 7NA, 11, Bleasdale, Heelands, Milton Keynes
    </div>


    <div class="pcaitem" title=
    "MK13 7NA, 12, Bleasdale, Heelands, Milton Keynes">
        MK13 7NA, 12, Bleasdale, Heelands, Milton Keynes
    </div>


    <div class="pcaitem" title=
    "MK13 7NA, 13, Bleasdale, Heelands, Milton Keynes">
        MK13 7NA, 13, Bleasdale, Heelands, Milton Keynes
    </div>


    <div class="pcaitem" title=
    "MK13 7NA, 14, Bleasdale, Heelands, Milton Keynes">
        MK13 7NA, 14, Bleasdale, Heelands, Milton Keynes
    </div>


    <div class="pcaitem" title=
    "MK13 7NA, 15, Bleasdale, Heelands, Milton Keynes">
        MK13 7NA, 15, Bleasdale, Heelands, Milton Keynes
    </div>


    <div class="pcaitem" title=
    "MK13 7NA, 16, Bleasdale, Heelands, Milton Keynes">
        MK13 7NA, 16, Bleasdale, Heelands, Milton Keynes
    </div>


    <div class="pcaitem pcalastitem" title=
    "MK13 7NA, 17, Bleasdale, Heelands, Milton Keynes">
        MK13 7NA, 17, Bleasdale, Heelands, Milton Keynes
    </div>
</div>

到目前为止,这是我的代码-它只返回运行时的国家列表,而不是实际地址,我怀疑它指向文档中的另一个pcaitem类.

代码语言:javascript
复制
;// Fileread, test, somefilename
fileread, AddressList, mk-data-000001-1.csv


IE := ComObjCreate("InternetExplorer.Application")
IE.Navigate("http://www.postcodeanywhere.co.uk/demos/address-finder/")
ComObjError(false)
IE.Visible := true


loop 14
{
Send {Tab down}{Tab up}
Sleep 200
}


loop, parse, AddressList, `n, `r
{
    Clipboard = %A_LoopField%
    Send, ^v


Name_Elements := IE.document.getElementsByClassName("pcaitem")
loop, % Name_Elements.length
{
Addr_text := Name_Elements[A_Index-1].innertext
} 
}

mk-数据样品含量-000001-1.csv

代码语言:javascript
复制
MK1 1AS
MK1 1AX
MK1 1BA
MK1 1BB
MK1 1BE
MK1 1BG
MK1 1BH
MK1 1BJ
MK1 1BL
MK1 1BN
MK1 1BP
MK1 1BQ
MK1 1BU
MK1 1BW
MK1 1BX
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-08-12 04:33:27

我相信你的假设是对的。我不觉得再精确一点会有什么坏处?

我使用了以下方法:

代码语言:javascript
复制
IE.document.getElementsByClassName("pcalist")[0].getElementsByClassName("pcaitem")

下面是一个测试示例

代码语言:javascript
复制
SetTitleMatchMode,2

IE := ComObjCreate("InternetExplorer.Application")
IE.Navigate("http://www.postcodeanywhere.co.uk/demos/address-finder/")
ComObjError(false)
IE.Visible := true
MsgBox Press OK when the page has been fully loaded.
Sleep 200
WinMaximize, Internet Explorer
Sleep 1000

;click the search input field
send {PGDN}
Sleep 200
x:=A_ScreenWidth//2
Click, %x% 250
Sleep 200

;search text
Send, MK1 1AS
Sleep 200

Data:=""
ResultsList := IE.document.getElementsByClassName("pcalist")[0].getElementsByClassName("pcaitem")
Loop % ResultsList.Length
    Data .= ResultsList[A_Index-1].innerHTML
StringReplace,Data,Data,</span>,`n,All
Data:=RegExReplace(Data,"<span[^<>]+>",", ")
MsgBox % Data

屏幕截图

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25223204

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档