【问题标题】:Quick and easy web automation/data scraping快速简单的网络自动化/数据抓取
【发布时间】:2019-06-05 20:59:51
【问题描述】:

我需要在一个不属于我的网站中输入大约 3 条数据,然后按提交,然后抓取一些数据。我需要使用不同的日期重复此操作大约 50 次。我以前在 Powershell 中重复使用过很多东西。但是,我想知道是否有一些简单的东西,比如点击鼠标,我可以像花费数小时一样使用它,我可以很容易地输入数据并将结果复制到电子表格中。

任何浏览器都可以。

【问题讨论】:

  • 这个问题是题外话,但你应该看看基于硒的方法:seleniumhq.org
  • 如果您可以捕获请求和表单数据,您可以修改并发送它而不是使用网页。
  • 那是公共网站吗?
  • 是的。这是一个公共网站。这是一个旅游网站。

标签: powershell google-chrome internet-explorer automation


【解决方案1】:

您可以尝试通过 VBA 使用 IE 自动化从 IE 中抓取数据并将其粘贴到 Excel 工作簿中。

例子:

Sub Automate_IE_Load_Page()
'This will load a webpage in IE
    Dim i As Long
    Dim URL As String
    Dim IE As Object
    Dim objElement As Object
    Dim objCollection As Object
 
    'Create InternetExplorer Object
    Set IE = CreateObject("InternetExplorer.Application")
 
    'Set IE.Visible = True to make IE visible, or False for IE to run in the background
    IE.Visible = True
 
    'Define URL
    URL = "https://www.example.com"
 
    'Navigate to URL
    IE.Navigate URL
 
    ' Statusbar let's user know website is loading
    Application.StatusBar = URL & " is loading. Please wait..."
 
    ' Wait while IE loading...
    'IE ReadyState = 4 signifies the webpage has loaded (the first loop is set to avoid inadvertently skipping over the second loop)
    Do While IE.ReadyState = 4: DoEvents: Loop   'Do While
    Do Until IE.ReadyState = 4: DoEvents: Loop   'Do Until
 
    'Webpage Loaded
    Application.StatusBar = URL & " Loaded"
    
    'Unload IE
    Set IE = Nothing
    Set objElement = Nothing
    Set objCollection = Nothing
    
End Sub 

参考资料:

(1)Automate Internet Explorer (IE) Using VBA

(2)VBA Web Scraping with GetElementsByTagName

(3)IE (Internet Explorer) Automation using Excel VBA

此外,您可以尝试根据您的要求修改代码。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-02
    相关资源
    最近更新 更多