繁体   English   中英

从具有特定值的标签中检索数据

[英]Retriving data from tags with a certain value

我一直在尝试在<strong>标记后获得在AHK中具有一定价值的文本。 说我对之后发生的事情感兴趣: <strong>Author(s): </strong> 这是一个尝试。 它几乎可以解决问题,但是输出字符串以一些空格开头。 (原始字符串没有空格)。 我该如何解决?

IE := ComObjCreate("InternetExplorer.Application")
IE.Visible := false
IE.Navigate("https://www.ceeol.com/search/article-detail?id=298665")

while IE.readyState != 4 || IE.document.readyState != "complete" || IE.busy
    Sleep 10

detail := IE.document.getElementsByClassName("article-detail-description")
div := detail[0].getElementsByTagName("div")
str := StrSplit(div[0].innerHTML, "<br>")

for index, val in str{
    if(InStr(val, "Author(s): ")){
        sName := StrReplace(val, "<strong>Author(s): </strong>")
        Break
    }
}

MsgBox, % sName
ExitApp

看起来您在返回的Div的开头处有空格-一些新行加上一些空格。 尝试:

    sName := Trim(SubStr(StrReplace(val, "<strong>Author(s): </strong>"), 2))

2是换行符和第一个空格字符。 由于后续字段将没有该换行符,因此您将更改为1:

if(InStr(val, "Keywords: ")){
    sName := Trim(SubStr(StrReplace(val, "<strong>Keywords: </strong>"), 1))

相当于您拥有的:

    sName := StrReplace(val, "<strong>Keywords: </strong>")

Hth,

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM