HTTP GET - Download and Parse HTML
Downloads an HTML page from the Singapore Exchange and parses a row of options prices from an HTML table.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
set http = Server.CreateObject("Chilkat_9_5_0.Http")
' Any string unlocks the component for the 1st 30-days.
success = http.UnlockComponent("Anything for 30-day trial")
If (success <> 1) Then
Response.Write http.LastErrorText & "<br>"
End If
' Send the HTTP GET and return the content in a string.
html = http.QuickGetStr("http://esite.sgx.com/live/dt/DTFuture.asp?JBFE")
' Use the Chilkat HTML-to-XML component to convert
' the HTML to parsable XML:
set htmlToXml = Server.CreateObject("Chilkat_9_5_0.HtmlToXml")
' Any string argument automatically begins the 30-day trial.
success = htmlToXml.UnlockComponent("30-day trial")
If (success <> 1) Then
Response.Write "HtmlToXml component unlock failed" & "<br>"
End If
' Indicate the charset of the output XML we'll want.
htmlToXml.XmlCharset = "utf-8"
' Set the HTML:
htmlToXml.Html = html
' We won't need the scripts or images, so drop those tags...
htmlToXml.DropTagType "img"
htmlToXml.DropTagType "script"
' Get the XML:
xmlStr = htmlToXml.ToXml()
' Load the XML into the Chilkat XML parser:
set xml = Server.CreateObject("Chilkat_9_5_0.Xml")
xml.LoadXml xmlStr
' success = xml.SaveXml("out.xml");
' Find a known point in the XML. In this case we'll look for the text node
' containing this string: "Chg From Prev Settle"
Set node = xml.SearchForContent(Nothing,"text","Chg From Prev Settle")
If (node Is Nothing ) Then
Response.Write "Did not find Chg From Prev Settle" & "<br>"
End If
' Move up to the TD node:
node.GetParent2
' Move up to the TR node:
node.GetParent2
' Move to the next row (i.e. next TR)
node.NextSibling2
node.FirstChild2
node.NextSibling2
Response.Write Server.HTMLEncode( "Expire Month/Year: " _
& node.GetChildContent("text")) & "<br>"
node.NextSibling2
Response.Write Server.HTMLEncode( "Last: " _
& node.GetChildContent("text")) & "<br>"
node.NextSibling2
Response.Write Server.HTMLEncode( "Change: " _
& node.GetChildContent("text")) & "<br>"
node.NextSibling2
' ...
success = node.SaveXml("row.xml")
%>
</body>
</html>
|