VBA Geht网页链接并将文件下载到

问题描述 投票:-1回答:1

很久以前对BA进行编程。

我想在Web表格中获取所有链接的PDF文件(x)

首先,我已经创建了登录名,并导航到该站点以获取文件。

站点表看起来是这样。enter image description here

Sub goToShopWH()

Dim ieApp As InternetExplorer
Dim ieDoc As Object
Dim clip As Object

'Table Grapping
Dim ieTable As Object

'create a new instance of ie
'Set ieApp = New InternetExplorer
Set ieApp = CreateObject("InternetExplorer.Application")

'you don’t need this, but it’s good for debugging
ieApp.Visible = True

'assume we’re not logged in and just go directly to the login page
ieApp.Navigate "https://website.com/ishop/Home.html"
Do While ieApp.Busy: DoEvents: Loop
Do Until ieApp.ReadyState = READYSTATE_COMPLETE: DoEvents:
Loop

' Login to site

Set ieDoc = ieApp.Document

'fill in the login form – View Source from your browser to get the control names
With ieDoc '.forms("loginForm_0")
 .getElementById("loginField").Value = "username"
 .getElementById("password").Value = "Password"
 .getElementById("loginSubmit").Click
  
 

Do While ieApp.Busy: DoEvents: Loop
Do Until ieApp.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop

'now that we’re in, go to the page we want
'Switsh to search form

ieApp.Navigate "https://website.com/ishop/account/MyAccount,$comp$account$AccountNavigation.orderHistory.sdirect?sp=Saccount%2FOrderHistory"
Do While ieApp.Busy: DoEvents: Loop
Do Until ieApp.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop

' fillout form

Set ieDoc = ieApp.Document
With ieDoc '.forms("Form_0")
 .getElementById("PropertySelection_2").Value = "7"
 .getElementById("commtxt").Value = "190055"  'Projekt Nummer oder Text.
 .getElementById("Submit_0").Click
  
End With


Do
DoEvents
Loop Until ieApp.ReadyState = 4

Application.Wait Now + TimeSerial(0, 0, 5)


With ieDoc '.forms("Form_1")
 .getElementById("PropertySelection").Value = "3"
 .getElementById("PropertySelection").FireEvent ("onchange")

End With

Do
DoEvents
Loop Until ieApp.ReadyState = 4
Application.Wait Now + TimeSerial(0, 0, 5)


End With

Set webpage = ieApp.Document

Set table_data = webpage.getElementsByTagName("tr")

End Sub

请帮助我解决此问题以获取我想将表格导入sheet2并在(“表格”),(“ tbody”)(tr)(1到X),(td)(10),(href)中下载所有PDF。单击

vba excel-vba html-table href tr
1个回答
0
投票

我测试了此代码以将信息放入工作表1

正在使用hyyperlink进行工作

Set webpage = ieApp.Document
' TR Zeilen Select
Set table_data = webpage.getElementsByTagName("Table")(6).getElementsByTagName("tr")


trowNum = 1
For Each trow In table_data
    For Each tcell In trow.Children
        tcellNum = tcellNum + 1
        Cells(trowNum, tcellNum) = tcell.innerText
    Next tcell
    trowNum = trowNum + 1
    tcellNum = 0
Next trow
© www.soinside.com 2019 - 2024. All rights reserved.