简体   繁体   English

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

[英]Retriving data from tags with a certain value

I have been trying to get text after <strong> tag that has a certain value in AHK. 我一直在尝试在<strong>标记后获得在AHK中具有一定价值的文本。 Say I am interested in what comes after: <strong>Author(s): </strong> . 说我对之后发生的事情感兴趣: <strong>Author(s): </strong> Here's an attempt to do so. 这是一个尝试。 It almost does the trick but the output string starts with some white space. 它几乎可以解决问题,但是输出字符串以一些空格开头。 (There is no white space is the original string). (原始字符串没有空格)。 How do I fix this? 我该如何解决?

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

Looks like you have white-space at the start of the returned Div -- some new line plus some spaces. 看起来您在返回的Div的开头处有空格-一些新行加上一些空格。 Try: 尝试:

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

The 2 is the linefeed and first space character. 2是换行符和第一个空格字符。 Since subsequent fields won't have that linefeed, you would change to 1: 由于后续字段将没有该换行符,因此您将更改为1:

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

which is equivalent to what you had: 相当于您拥有的:

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

Hth, Hth,

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

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