将不同网站的特定字段复制到工作表

我需要一个VBScript,可以用来复制不同的网页输出,并将其复制到Excel表

例:

像truecaller.Com网站,您可以通过电话号码search人。 每个数字代表独特的url(www.truecaller.com/au/439965324)我需要做一个有两列的Excel表格; 第一个是url,第二个是8的相关名称

Excel VBA不是最好的网页抓取,但它可以完成工作。
首先,您需要确保您下载最新的Internet Explorer,或者至less确保您拥有版本9或更高版本。
其次,你必须在macros上启用一些引用(这类似于像Java这样的语言的引入)。 要做到这一点,打开你的VBA编辑器,并转到工具>参考。 您需要勾选Microsoft Internet控件Microsoft HTML对象库

在这里输入图像说明
现在你很好走,下面的代码应该为你工作。 不是真正的来电者,我只在名称字段中看到“ – ”,但是如果你有一个帐户,我想它是不同的。 我所做的脚本只是简单地列出名字,号码和地址。 我相信你不会有一个问题,循环你想要的url,然后把抓取的数据放在你想要的地方。

Sub Test() 'to refer to the running copy of Internet Explorer Dim ie As InternetExplorer 'to refer to the HTML document returned Dim html As HTMLDocument 'open Internet Explorer in memory, and go to website Set ie = New InternetExplorer ie.Visible = False ie.navigate "www.truecaller.com/au/439965324" 'Wait until IE is done loading page Do While ie.readyState <> READYSTATE_COMPLETE Application.StatusBar = "Trying to go to StackOverflow ..." DoEvents Loop 'show text of HTML document returned Set html = ie.document MsgBox html.DocumentElement.innerHTML Dim element As IHTMLElement Set element = html.getElementsByClassName("result__details")(0) Dim Name As String Dim Number As String Dim Address As String Name = element.Children(0).Children(1).innerText Number = element.Children(1).Children(1).innerText Address = element.Children(2).Children(1).innerText MsgBox ("Name is " & Name & " with number " & Number & ". Address: " & Address) 'close down IE and reset status bar Set ie = Nothing Application.StatusBar = "" End Sub 

如果你想了解更多关于VBA的信息,那么这里有一个很好的链接:
http://www.wiseowl.co.uk/blog/s393/scraping-websites-vba.htm