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

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

很早以前就对VBA进行编程。我想在Web表中获取coll(x)中所有链接的PDF文件。首先,我创建了登录名并导航到该站点以获取文件。站点表:

<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9TS3l2VS5wbmcifQ==” alt =“在此处输入图像描述”>

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 )。单击

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.