【问题标题】:Selecting a dropdown from a web site从网站中选择下拉列表
【发布时间】:2020-05-30 18:09:44
【问题描述】:

这是我第一次尝试从网页中提取 Excel 报告。我的代码应该如何工作的顺序如下:

  1. 初始 URL - 将网站主页(保存在浏览器中的用户 ID 和密码自动登录) - image1
  2. 点击“报告”
  3. 出现新页面 (image2)
  4. 从下拉模块中选择。
  5. 从 dropdown_reports 中选择适当的。
  6. 在 dropdown_reports 中的选择会创建一个新的 dropdown_project。
  7. 从下拉项目中选择
  8. 点击下载报告 (image3)
  9. 给出下载路径。

    image41 image12 image23 image34

我能够到达第 3 点,但无法继续前进。 在 dropdown_module 上使用检查元素时,我得到了代码 (image4)

我目前的使用情况如下:

Set IE = CreateObject("InternetExplorer.Application")
URL = Range("hr_url").Value
IE.Visible = True
IE.navigate URL
Application.StatusBar = " is loading. Please wait..."
Do While IE.readyState = 4: DoEvents: Loop
Do Until IE.readyState = 4: DoEvents: Loop
Application.StatusBar = " Loaded"

Set doc = IE.document
For Each element In doc.all
    If InStr(element.ID, "08191") > 0 Then
        If InStr(element.ID, "AppPress:12") Then
            element.Focus
            element.Click
        End If
    End If
Next element

Application.Wait (5)


Do
DoEvents
Loop Until IE.readyState <> 4

Set doc = IE.document
For Each element In doc.all
    If InStr(element.ID, "0261") > 0 Then
        If InStr(element.ID, "AppPress:6") Then
          MsgBox "element is found"
          element.Options(0).Selected = True
        End If
    End If
Next element

代码无法找到下拉元素并选择所需的 0 索引。谁能建议这里有什么问题?

【问题讨论】:

    标签: excel vba dropdown


    【解决方案1】:

    我不知道使用 VBA 可以进行抓取。 (刮痧是利用软件从网络中提取信息的技术被称为)

    你应该会发现这个问题很有用:

    Scraping data from website using vba

    我不知道使用 VBA 执行此操作的可能性可能仅限于 Internet Explorer 以及其他限制。我为此做的一些小事情是使用 python 和一个名为 beautifulSoup 的库,太棒了!

    https://www.crummy.com/software/BeautifulSoup/bs4/doc/

    如果您感到足够好奇,您可能想深入研究它,因为它非常简单,并且在谷歌上搜索您想做的事情可能会让您走得很远,如果您想使用提取的信息创建一个 excel 文件也是如此。

    希望有帮助

    【讨论】:

      猜你喜欢
      • 2023-04-03
      • 2018-04-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-19
      相关资源
      最近更新 更多