【发布时间】:2018-10-09 12:31:15
【问题描述】:
我已经使用WinHTTP 自己克服了连接问题(这是响应文本方法的Debug.Print 错误)。
所以我必须从一个表单(超过 20 个)中获取很多值,然后创建一个字符串并将其传递给 http://exampletry.it/visualizzaelenco.do 以生成 PDF 文件。
这是一个表单代码示例。
<BODY>
<form name="trattamentoForm" method="post" action="/ecportal/trattamento_dettaglio.do">
<input type="hidden" name="service" value="">
<input type="hidden" name="ufficioLoggato" value="">
<input type="hidden" name="uff_comp" value="DZT">
<input type="hidden" name="profiloUtente" value="U">
<input type="hidden" name="tipoModelloRicerca.codice" value="V">
<input type="hidden" name="tipoModelloRicerca.descrizioneEstesa" value="V - MODELLO V">
<input type="hidden" name="partRicerca" value="">
<input type="hidden" name="annoRicerca" value="">
<input type="hidden" name="codiceRicerca" value="123456789">
<input type="hidden" name="dataPresRicerca" value="">
<input type="hidden" name="numProtRicerca" value="">
<input type="hidden" name="concessionarioRicerca.codice" value="">
......
那么如何在不使用标记名的情况下获取名称和值?我正在使用 WinHTTP,我不想使用 IE 或其他网络浏览器。 (我只能使用.click 和 VBA 和 IE 来做到这一点)
添加代码
oHtml.body.innerHTML = http.responseText
If http.Status = 200 Then
Set OSTREAM = CreateObject("ADODB.Stream")
OSTREAM.Open
OSTREAM.Type = 1
OSTREAM.Write http.responseBody
File1 = "E:\test.html"
OSTREAM.SaveToFile File1, 2
OSTREAM.Close
End If
Dim html As HTMLDocument
Set html = GetHTMLFileContent("E:\test.html")
Dim list As Object, i As Long
Set list = html.querySelectorAll("trattamentoForm")
For i = 0 To list.length - 1
Debug.Print "Name: " & list.Item(i).Name, "Value: " & list.Item(i).Value
Next
【问题讨论】:
标签: excel vba web-scraping winhttp