从网站使用VBA刮,但它不工作。 该怎么办?

我有这个网站: http : //ga.healthinspections.us/georgia/search.cfm?start=21&1=1&f=s&r=ANY&s=&inspectionType=Food&sd=03/26/2016&ed=04/25/2016&useDate=NO&county=Fulton&

而且我已经写了代码,但即使第一页也不起作用。 我的目标是从每个页面提取以下build立的详细信息作为示例:

Column 1: 103 West Lounge (Food Service Inspections) Column 2: 103 WEST PACES FERRY RD ATLANTA, GA 30318 (Skip this detail) View inspections: Column 3: July 10, 2012 Score: 92, Grade: A Column 4): July 26, 2013 Score: 90, Grade: A Column 5): February 19, 2014 Score: 98, Grade: A Column 6): December 12, 2014 Score: 100, Grade: A Column 6): November 13, 2015 Score: 99, Grade: A 

目前,代码只是从不知情的地方提取URL,并且需要检查要更改或错误的内容:

 Sub Test() Dim IE As New InternetExplorer Dim html As HTMLDocument Dim link As Object Dim ws As Worksheet Set ws = Sheets("Sheet1") Application.ScreenUpdating = False Set IE = New InternetExplorer ' Test 2 pages (page 2 and page 3) starting from page 2. So far so good. For i = 2 To 4 Step 2 myurl = "http://ga.healthinspections.us/georgia/search.cfm?start=" & i & "1&1=1&f=s&r=ANY&s=&inspectionType=Food&sd=03/26/2016&ed=04/25/2016&useDate=NO&county=Fulton&" IE.Visible = False IE.navigate myurl Do DoEvents Loop Until IE.readyState = READYSTATE_COMPLETE Set html = IE.document ' I assume here is the problem, because I need to supplement code part to find these details. Set link = html.getElementsByTagName("a") ' This part was intended to test if I can to extract at least one detail. For m = 1 To 2 For Each myurl In link Cells(m, 1) = link Next Next m Next i 'Also I tried to test with msgbox but no luck either 'MsgBox link IE.quit Set IE = Nothing Application.StatusBar = "" Application.ScreenUpdating = True End Sub 

也许有些东西是混乱的,或者我缺乏知识。 :)希望得到任何帮助。

你有参考设置? 对于Microsoft Internet控件和Microsoft HTML对象库? 如果是这样,请尝试replace代码段。

 Dim IE As New InternetExplorer Dim html As MSHTML.HTMLDocument Dim link As Object Dim ws As Worksheet Set ws = Sheets("Sheet1") Application.ScreenUpdating = False Set IE = New InternetExplorer 

您可以使用下面的方法获取无限文本。

 Sub DumpData() Set IE = CreateObject("InternetExplorer.Application") IE.Visible = True URL = "http://ga.healthinspections.us/georgia/search.cfm?start=1&1=1&f=s&r=ANY&s=&inspectionType=Food&sd=03/26/2016&ed=04/25/2016&useDate=NO&county=Fulton&" 'Wait for site to fully load IE.Navigate2 URL Do While IE.Busy = True DoEvents Loop RowCount = 1 With Sheets("Sheet1") .Cells.ClearContents RowCount = 1 For Each itm In IE.Document.all .Range("A" & RowCount) = itm.tagName .Range("B" & RowCount) = itm.ID .Range("C" & RowCount) = itm.className .Range("D" & RowCount) = Left(itm.innerText, 1024) RowCount = RowCount + 1 Next itm End With End Sub 

我从一个叫Joel的大个子那里得到了这个。 他是这个东西的智者。

一旦你的数据被导入你的工作表,做一些简单的清理,摆脱多余的东西,你应该全部设置。