【发布时间】:2019-04-26 19:20:55
【问题描述】:
在此链接的 QHarr 代码中 Retrieving all Excel file links from a webpage with Excel VBA
Public Sub Links()
Dim sResponse As String, html As HTMLDocument, list As Object, i As Long
With CreateObject("MSXML2.XMLHTTP")
.Open "GET", "https://www.jpx.co.jp/markets/public/short-selling/index.html", False
.setRequestHeader "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT"
.send
sResponse = StrConv(.responseBody, vbUnicode)
End With
Set html = New HTMLDocument
With html
.body.innerHTML = sResponse
Set list = html.querySelectorAll("[href$='.xls']")
End With
For i = 0 To list.Length - 1
Debug.Print Replace$(list.item(i), "about:", "https://www.jpx.co.jp")
Next
End Sub
我正在尝试以另一种方式使用 CSS 选择器.. 我使用了这个 img[title='Excel'] 但这会返回对象而不是此选择器之前的链接 问题是如何引用前面的标签,它是一个标签..?
【问题讨论】:
-
指定具有特定子代的 a 标签:
a img[title=‘Excel’]? -
非常感谢。但这会返回代码中的对象列表
-
另一个 xpath 将是
"//a[img[@title='Excel']]"。 -
这也很好。非常感谢
标签: css excel vba web-scraping xmlhttprequest