Macro para extraer información de una tabla HTML
Publicado por Eduardo (3 intervenciones) el 24/01/2020 18:02:02
Hola buen día
Tengo el sig. código para extraer la información de una pagina web a mi Excel, quisiera saber si hay una forma para hacer que solo tome una de las tablas en la pagina y si hay una forma de hacer que repita el proceso con varios URL ya que toda la información que necesito extraer esta en 378 url distintas que solo cambia el ultimo numero de manera incremental(ej. P1130,P1131,P1132...). Agradecería cualquier ayuda que me encamine a resolver el problema.
Tengo el sig. código para extraer la información de una pagina web a mi Excel, quisiera saber si hay una forma para hacer que solo tome una de las tablas en la pagina y si hay una forma de hacer que repita el proceso con varios URL ya que toda la información que necesito extraer esta en 378 url distintas que solo cambia el ultimo numero de manera incremental(ej. P1130,P1131,P1132...). Agradecería cualquier ayuda que me encamine a resolver el problema.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
Sub WebDataImport()
On Error GoTo ControlErr
Dim strURL As String
Dim strDestino As String, strReportName As String
Dim numConnections As Integer, i As Integer
'vars
numConnections = ThisWorkbook.Connections.Count
strDestino = "A1"
strReportName = "Reporte Mensual"
strURL = InputBox("Indique URL origen", "Mensaje")
'check url data
If strURL <> Empty Then
'custom url address
strURL = "URL;" & strURL
'clean previous connections
If numConnections > 0 Then
For i = 1 To numConnections
ThisWorkbook.Connections(i).Delete
Next i
End If
'clean datasheet
Sheets(1).Select
Sheets(1).Cells.Clear
'control excel app
Application.ScreenUpdating = False
'get web query
With Sheets(1).QueryTables.Add(Connection:=strURL _
, Destination:=Range(strDestino))
.Name = strReportName
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
'control excel app
Application.ScreenUpdating = True
'final message
MsgBox "La importación ha finalizado", vbInformation, "Mensaje"
End If
Exit Sub
ControlErr:
MsgBox "Error: " & Err.Description, vbCritical, "Mensaje"
End Sub
Valora esta pregunta


0