excelvba抓取网页数据(使用VBA宏将表格数据从多个网页提取到Excel中..! )

优采云 发布时间: 2021-10-25 23:22

  excelvba抓取网页数据(使用VBA宏将表格数据从多个网页提取到Excel中..!

)

  使用 VBA 宏从多个网页中提取表格数据到 Excel.. !! 目前我使用下面的链接,但我只能在代码中使用一个网页..我有一个 ulr 列表来获取数据......它必须是垂直的......!请建议我.. :)

  Sub INDEXdata()

With ActiveSheet.QueryTables.Add(Connection:= _

"URL;http://recorder.maricopa.gov/recdocdata/GetRecDataDetail.aspx?rec=19770000007" _

, Destination:=Range("$A$1"))

.Name = "rec=19770000006"

.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,3"

.WebPreFormattedTextToColumns = True

.WebConsecutiveDelimitersAsOne = True

.WebSingleBlockTextImport = False

.WebDisableDateRecognition = False

.WebDisableRedirections = False

.Refresh BackgroundQuery:=False

End With

End Sub

  1 个回答:

  答案 0:(得分:0)

  好吧,我不知道您有多少编程背景,也不知道您发布的代码的哪些部分特定于该源 URL 和目标位置。

  但是,这样的事情可能会有用。我假设您要提取的每个页面的 URL、目的地和名称都会更改。

  我所做的是将似乎适用于所有源页面和目标的代码部分放入我自己的参数化子例程中。原创例程 IndexData 仅指定每个复制操作的 URL、目标和名称。

   Sub IndexData()

GetData("http://recorder.maricopa.gov/recdocdata/GetRecDataDetail.aspx?rec=19770000007" , _

"$A$1", _

"rec=19770000006")

GetData("http://somewhereelse.com/somedata.aspx?rec=12345", _

"$A$2", _

"rec=12345")

GetData("http://anotherurl.com/etc", _

"$A$3", _

"something")

End

Sub GetData(url as string, destination as string, name as string)

With ActiveSheet.QueryTables.Add(Connection:= _

"URL;" & url , Destination:=Range(destination))

.Name = name

.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,3"

.WebPreFormattedTextToColumns = True

.WebConsecutiveDelimitersAsOne = True

.WebSingleBlockTextImport = False

.WebDisableDateRecognition = False

.WebDisableRedirections = False

.Refresh BackgroundQuery:=False

End With

End Sub

0 个评论

要回复文章请先登录注册


官方客服QQ群

微信人工客服

QQ人工客服


线