Excel 2010を使用しています。XMLHTTPオブジェクトを使用してフォームデータを送信しようとしています。私が働いているウェブサイトはhttp://espn.go.com/mlb/playersです。検索ボックス(Fisterなど)で特定のプレイヤーを検索しようとしています。ここにフォームタグ間のソースコードがあります。VBAでXMLHTTPを使用してフォームデータを送信
<form id="searchBox" name="searchBox" action="http://search.espn.go.com/results" method="get" accept-charset="utf-8" style="color: #999999;">
<div class="clearfix">
<input autocomplete="off" class="text" type="text" placeholder="Search" name="searchString" id="searchString" />
<input type="hidden" name="page" id="page" value="null" />
<input type="hidden" name="fromForm" value="true" />
<input class="submit" type="submit" value="" />
</div>
</form>
検索を行うためのコードは次のとおりです。
Sub SearchPlayer()
Dim xml As MSXML2.ServerXMLHTTP
Dim search, url As String
search = "searchString=Fister&page=null&fromForm=true"
url = "http://espn.go.com/mlb/players"
Set xml = New MSXML2.ServerXMLHTTP
xml.Open "POST", url, False
xml.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xml.send search
MsgBox xml.responseText
Set xml = Nothing
End Sub
HtmlフォームはGETメソッドを使用し、コードサンプルはPOSTを使用します。 – Filburt