Excel 使用WinHTTP在表单中刮取标记输入

Excel 使用WinHTTP在表单中刮取标记输入,excel,vba,web-scraping,winhttp,Excel,Vba,Web Scraping,Winhttp,我自己用WinHTTP解决了连接问题(这是响应文本方法的Debug.Print错误) 因此,我必须从一个表单(超过20个)中获取大量值,然后创建一个字符串并将其传递给http://exampletry.it/visualizzaelenco.do以生成PDF文件 这是表单代码的一个示例 <BODY> <form name="trattamentoForm" method="post" action="/ecportal/trattamento_dettaglio.do">

我自己用
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="">
......

我承认我不清楚你想做什么。假设您在表单中输入标记元素的属性
value
name
之后,您可以使用CSS选择器以具有name属性的所有表单元素为目标,并读取结果匹配的元素name和value属性值。此外,假设每个元素都有名称和值属性(看起来是)


太多了!我使用了您的代码,但在GetHTMLFileContent(未定义子函数或函数…)上收到一个错误。我在原始帖子中添加了代码。这是因为它是我从文件读取的帮助函数。您应该使用下面的示例来填充html。我会调整的。格雷特。。。我在html中添加了一个“o”…我的错误…并删除了表单中的名称。。。所以我必须得到每个“name”和“value”,并创建一个字符串,比如name1=value1&name2=value2&。。。将winhttp post请求发送到“Visualizadettaglio.do”并生成.pdf
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
Option Explicit
Public Sub test()
    Dim html As HTMLDocument
    Set html = New HTMLDocument
    With CreateObject("WINHTTP.WinHTTPRequest.5.1")
        .Open "GET", "yourURL", False
        .send
        html.body.innerHTML = .responseText
    End With

    Dim list As Object, i As Long
    Set list = html.querySelectorAll("form input[name]")
    For i = 0 To list.Length - 1
        Debug.Print "Name: " & list.item(i).NAME, "Value: " & list.item(i).Value
    Next
End Sub