我正在尝试使用CSS选择器从网站抓取特定数据。我在QHar的帮助下成功完成了工作,但现在的要求已经改变。这是我的代码如下:
代码
Public Sub CompanyData2()
Dim html As HTMLDocument,ws As Worksheet,re As Object
Set re = CreateObject("VBScript.RegExp")
re.Pattern = "\s{2,}"
Set ws = ThisWorkbook.Worksheets("Sheet1")
Set html = New HTMLDocument
With CreateObject("MSXML2.XMLHTTP")
.Open "GET","https://www.bizi.si/iskanje?q=",False
.send
html.body.innerHTML = .responseText
End With
ws.Range("A4").Value = re.Replace(Join$(Array(html.querySelector("td.item a").innerText),","),Chr$(32))
ws.Range("A5").Value = re.Replace(Join$(Array(html.querySelector("td.item + td.item").innerText),Chr$(32))
ws.Range("B6").Value = re.Replace(Join$(Array(html.querySelector("td.item + td.item + td.item + td.item").innerText),Chr$(32))
End Sub
结果如下:
网站
我想这样提取工作表1 A3上的公司名称:
谢谢。