如何访问在AHK上运行时生成的HTML?
在将邮政编码粘贴到搜索框(本网站- http://www.postcodeanywhere.co.uk/demos/address-finder/)后,我正在尝试访问下拉框的内容。

对于两个条目,网页代码如下:
<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+条目,网页代码如下:
<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类.
;// 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
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发布于 2014-08-12 04:33:27
我相信你的假设是对的。我不觉得再精确一点会有什么坏处?
我使用了以下方法:
IE.document.getElementsByClassName("pcalist")[0].getElementsByClassName("pcaitem")下面是一个测试示例
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屏幕截图

https://stackoverflow.com/questions/25223204
复制相似问题