我正在尝试使用我相当基本的 excel 技能来抓取大量数据。我将此用作指南(http://www.familycomputerclub.com/scrpae-pull-data-from-websites-into-excel.html),并且已经让它为我的数据工作,但现在试图修改代码满足我的要求。
我在列中列出了大约 10,000 个卷号,需要从该站点抓取数据(最后 10 位是卷号):http ://www.winnipegassessment.com/AsmtPub/english/propertydetails/details.aspx?pgLang =EN&isRealtySearch=true&RollNumber=2011016000
基本上,我不想为每个页面下载添加新工作表(根据我上面一直使用的指南),我想将所有新数据保留在母版页上,只需将其转换到具有相应卷号的行中(可能来自 C 列)。
我的代码如下:
Sub adds()
For x = 1 To 5
Worksheets("RollNo").Select
Worksheets("RollNo").Activate
mystr = "URL;http://www.winnipegassessment.com/AsmtPub/english/propertydetails/details.aspx?pgLang=EN&isRealtySearch=true&RollNumber=2000416000.html"
mystr = Cells(x, 1)
Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = x
With ActiveSheet.QueryTables.Add(Connection:=mystr, Destination:=Range("$A$2"))
'CommandType = 0
.Name = "2000416000_1"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "2,6,7" '---> Note: many tables have been selected for import from the website
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
Next x
End Sub