打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Excel QueryTables的批量抓取办法(两个变量的处理)

[原创]QueryTables的批量抓取办法(两个变量的处理)[复制链接]

本帖最后由 引子玄 于 2012-7-18 15:36 编辑

问:EXCEL 如何获取网站多页数据?地址 http://www.sdzs.gov.cn/score/gaokao/2012/0715/Book1.htm
==================
答:
先通过QueryTables获取分页URL
得出分页URL为:
http://www.sdzs.gov.cn/score/gaokao/2012/0715/Book1.files/sheet001.htm
http://www.sdzs.gov.cn/score/gaokao/2012/0715/Book2.files/sheet001.htm
http://www.sdzs.gov.cn/score/gaokao/2012/0715/Book3.files/sheet001.htm
http://www.sdzs.gov.cn/score/gaokao/2012/0715/Book4.files/sheet001.htm
http://www.sdzs.gov.cn/score/gaokao/2012/0715/Book5.files/sheet001.htm

再做循环处理:
先QueryTables宏录制代码为:
Sub Macro1()
    With ActiveSheet.QueryTables.Add(Connection:= _
        "URL;http://www.sdzs.gov.cn/score/gaokao/2012/0715/Book1.files/sheet001.htm", _
        Destination:=Range("A1"))
        .Name = "sheet001"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .WebSelectionType = xlAllTables
        .WebFormatting = xlWebFormattingNone
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .Refresh BackgroundQuery:=False
    End With
End Sub

然后修改:
1、如果按行植入,代码

Sub 翻动网页按行植入()
x = 0
Do
x = x + 1
    With ActiveSheet.QueryTables.Add(Connection:= _
        "URL;http://www.sdzs.gov.cn/score/gaokao/2012/0715/Book" & x & ".files/sheet001.htm", _
        Destination:=Cells(60 * (x - 1) + 1, 1))
        .Name = "sheet001"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .WebSelectionType = xlAllTables
        .WebFormatting = xlWebFormattingNone
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .Refresh BackgroundQuery:=False
    End With
Loop Until x = 5
End Sub

2、如果按列植入,代码
Sub 翻动网页按列植入()
x = 0
Do
x = x + 1
    With ActiveSheet.QueryTables.Add(Connection:= _
        "URL;http://www.sdzs.gov.cn/score/gaokao/2012/0715/Book" & x & ".files/sheet001.htm", _
        Destination:=Cells(1, 12 * (x - 1) + 1))
        .Name = "sheet001"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .WebSelectionType = xlAllTables
        .WebFormatting = xlWebFormattingNone
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .Refresh BackgroundQuery:=False
    End With
Loop Until x = 5
End Sub
====================
QueryTables网页抓取的批量处理,最主要的是解决好URL和Range两个基本变量的问题。
学会对这两个变量的处理,那么网页抓取的门槛,难度将随之降低、、、、、、

千万别小瞧QueryTables,帮助寻找URL作用可大呢!
QueryTables结合F12键和IE功能,这样那样的隐藏看不见的URL,统统可以擒入囊中。(没有啥么装这装那工具的繁琐,只要一个IE浏览器就可以),而且对页面看得见的内容,统统都可以实现导入(直接或间接)。
QueryTables真可谓“只要看得见、就能抓得到”,是一款适众、通用、简易的抓取武器。
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
考生必读:2013年福建高考志愿填报相关参考资料整理
<font face="Helvetica" size="6">手把手教你“怎么填报正规的统招高考志愿”(附图片)</font>
高中数学知识点最全的思维导图
食品标准目录CAC&GB
让上网最爽
高考报志愿一定要知道的网站,后悔没早看
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服