从具有特定值的标签中检索数据
Retriving data from tags with a certain value
我一直试图在 <strong>
标签之后获取在 AHK 中具有特定值的文本。假设我对后面的内容感兴趣:<strong>Author(s): </strong>
。这是这样做的尝试。它几乎可以解决问题,但输出字符串以一些白色 space 开头。 (没有白的space是原字符串)。我该如何解决这个问题?
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 开头有白色-space -- 一些新行加上一些 space。尝试:
sName := Trim(SubStr(StrReplace(val, "<strong>Author(s): </strong>"), 2))
2 是换行符和第一个 space 字符。由于后续字段不会有该换行符,您将更改为 1:
if(InStr(val, "Keywords: ")){
sName := Trim(SubStr(StrReplace(val, "<strong>Keywords: </strong>"), 1))
这相当于你拥有的:
sName := StrReplace(val, "<strong>Keywords: </strong>")
Hth,
我一直试图在 <strong>
标签之后获取在 AHK 中具有特定值的文本。假设我对后面的内容感兴趣:<strong>Author(s): </strong>
。这是这样做的尝试。它几乎可以解决问题,但输出字符串以一些白色 space 开头。 (没有白的space是原字符串)。我该如何解决这个问题?
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 开头有白色-space -- 一些新行加上一些 space。尝试:
sName := Trim(SubStr(StrReplace(val, "<strong>Author(s): </strong>"), 2))
2 是换行符和第一个 space 字符。由于后续字段不会有该换行符,您将更改为 1:
if(InStr(val, "Keywords: ")){
sName := Trim(SubStr(StrReplace(val, "<strong>Keywords: </strong>"), 1))
这相当于你拥有的:
sName := StrReplace(val, "<strong>Keywords: </strong>")
Hth,