VBA废品网站获取所有艺术家的名字和专辑?

好吧,我完全不知道我需要做什么关于这个话题…

这里是代码。 我首先从网站上获取一些链接,然后我应该按照链接链接并从该网站获取一些数据…

Sheets("LINKS TEMP").Activate Dim httpObject As Object Set httpObject = CreateObject("MSXML2.XMLHTTP") Dim doc As Object Set doc = CreateObject("htmlfile") Dim links As Variant Dim l As Variant With httpObject .Open "GET", "http://www.smoothjazz.com/charts/", False .Send Do Until httpObject.ReadyState = 4 Loop doc.body.innerhtml = .responseText Set links = doc.getElementsByTagName("a") I = 1 For Each l In links Sheets("LINKS TEMP").Cells(I, 2).Value = l.href I = I + 1 Next l End With Sheets("LINKS TEMP").Activate lrLINKS = Cells(Rows.Count, "B").End(xlUp).Row copyLINKS = 1 For deleteLINKS = 1 To lrLINKS If Cells(deleteLINKS, 2).Value Like "*votesbytrack*" Then GoTo copyLOOP GoTo nextLOOP copyLOOP: Cells(deleteLINKS, 2).Copy Cells(copyLINKS, 1).PasteSpecial xlPasteValues copyLINKS = copyLINKS + 1 nextLOOP: Next deleteLINKS LRlinks2 = Cells(Rows.Count, "A").End(xlUp).Row For formatLINKS = 1 To LRlinks2 Cells(formatLINKS, 1).Value = "http://smoothjazz.com/charts/" & Right(Cells(formatLINKS, 1), Len(Cells(formatLINKS, 1)) - 6) nextLINK = Sheets("LINKS TEMP").Cells(formatLINKS, 1).Text Range("B:B").ClearContents With httpObject .Open "GET", Sheets("LINKS TEMP").Cells(formatLINKS, 1).Text, False .Send Do Until httpObject.ReadyState = 4 Loop doc.body.innerhtml = .responseText Set elem = doc.getElementsByClassName("trackingalbumname") x = 1 For Each l In elem Sheets("HEADER TEMP").Cells(x, 1).Value = l.span x = x + 1 Next l End With Next formatLINKS 

为什么它与GetElementsByClassName分开?

这里是HTML:

 <div class='content'> <p>&nbsp;</p> <table width="601" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="trackingtitle"> <span class="trackingartistname">NATHAN EAST<br/></span> <span class="trackingalbumname">Reverence <br/></span> 

它只是一个艺术家/专辑,但它需要跑遍整个HTML并find它们!

我需要做什么…除了开始学习努力?

我通常使用InternetExplorer.Application而不是MSXML2.XMLHTTP。 而且我听说htmlfile从IE 11被弃用,将不再工作。 至于getelementsbyclassname。 它应该是.document.getelementsbyclassname。 此外,不知道你是否想要“跨度”或属性。 我用标记名作为演示。 为了获得艺术家的价值,交换标记名为innertext或innerhtml。 您可以观察本地窗口中的对象属性并逐步执行代码。 查找与您要删除的数据相匹配的属性值。

 Sheets("LINKS TEMP").Activate Dim httpObject As Object Set httpObject = CreateObject("InternetExplorer.Application") Dim doc As Object ' Set doc = CreateObject("Shell.Application") Dim links As Variant Dim l As Variant With httpObject .navigate "http://www.smoothjazz.com/charts/" Do Until httpObject.ReadyState = 4 DoEvents Loop .Visible = True End With Set doc = httpObject Set elem = doc.document.getElementsByClassName("first") x = 1 For Each l In elem Sheets("HEADER TEMP").Cells(x, 1).Value = l.tagname x = x + 1 Next l 

在这里输入图像说明