【问题标题】:macro to import website table(s) into excel将网站表格导入 excel 的宏
【发布时间】:2017-04-23 13:40:37
【问题描述】:

我对所有编码(学术/心理学家)真的很陌生,我试图从这个站点提取数据来创建我的own local database

我的方法(我找不到“列出所有”功能)是使用我在 VBA 中从几个来源(见下文)编译的代码查询英国邮政编码区,即 AB1,see here

Sub GetCourseList()

Dim URL As String
Dim qt As QueryTable
Dim ws As Worksheet

Set ws = Worksheets.Add

URL = "https://register.fca.org.uk/shpo_searchresultspage?search=AB1&TOKEN=3wq1nht7eg7tr"

Set qt = ws.QueryTables.Add( _
    Connection:="URL;" & URL, _
    Destination:=Range("A1"))

With qt
    .RefreshOnFileOpen = True
    .Name = "CoursesFromWiseOwl"
    .FieldNames = True
    .WebSelectionType = xlAllTables
    .Refresh BackgroundQuery:=False
End With

End Sub

我的问题有 3 个:

  1. 我想为所有 3000 多个英国邮政编码区重复此操作(我可以获得一份清单)
  2. 我想删除它返回的多余行(如果您运行代码 1-22 和 548+,但每个地区会有所不同)
  3. 我想将所有数据编译到 1 个数据库,而不是 3000 个单独的工作表。

excel getdata/webquery/table 1(使用this URL 几乎完全符合我的要求,只是它只返回第 1 页,但我无法弄清楚如何自动化/缝合我想要的代码!

谁能帮我解决这个问题?

干杯

Seb

ps 抱歉忘记添加我不直接从直接页面抓取的原因是使用了 2 种不同类型的个人页面(见下文),这些页面似乎没有任何可预测的在 URL 中生成 ID 的方法。我将编写第二个查询,以同样的方式扫描 FCA 编号,以使用更完整的数据填充第二个数据库。

(register.fca.org.uk/ShPo_FirmDetailsPage?id=001b000000MfTlAAAV 和

fca-consumer-credit-interim.force.com/CS_RegisterSearchPageNew?accId=210552)

【问题讨论】:

    标签: database excel web vba


    【解决方案1】:

    下面的脚本将为您执行循环。我会留给你做清理工作。提示,提示...使用宏记录器。

    Sub GetCourseList()
    
    Dim URL As String
    Dim qt As QueryTable
    Dim ws As Worksheet
    
    Set ws = Worksheets.Add
    
    Dim lastRow As Long
    lastRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
    
    variable = 1
    Here:
    URL = "https://register.fca.org.uk/shpo_searchresultspage?search=AB" & variable & "&TOKEN=3wq1nht7eg7tr"
    
    lastRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
    
    Set qt = ws.QueryTables.Add( _
        Connection:="URL;" & URL, _
        Destination:=Range("A" & lastRow))
    
    With qt
        .RefreshOnFileOpen = True
        .Name = "CoursesFromWiseOwl"
        .FieldNames = True
        .WebSelectionType = xlAllTables
        .Refresh BackgroundQuery:=False
    End With
    
    variable = variable + 1
    GoTo Here:
    
    End Sub
    

    我要说的最后一件事是,R 会为你做很多、很多、很多的事情。如果我是你,我会用 R 来做这种事情。

    https://www.r-bloggers.com/search/web%20scraping/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-16
      相关资源
      最近更新 更多