Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
HTTP GET - Download and Parse HTMLDownloads an HTML page from the Singapore Exchange and parses a row of options prices from an HTML table. LOCAL loHttp LOCAL lnSuccess LOCAL lcHtml LOCAL loHtmlToXml LOCAL lcXmlStr LOCAL loXml LOCAL loNode loHttp = CreateObject('Chilkat.Http') * Any string unlocks the component for the 1st 30-days. lnSuccess = loHttp.UnlockComponent("Anything for 30-day trial") IF (lnSuccess <> 1) THEN =MESSAGEBOX(loHttp.LastErrorText) QUIT ENDIF * Send the HTTP GET and return the content in a string. lcHtml = loHttp.QuickGetStr("http://esite.sgx.com/live/dt/DTFuture.asp?JBFE") * Use the Chilkat HTML-to-XML component to convert * the HTML to parsable XML: loHtmlToXml = CreateObject('Chilkat.HtmlToXml') * Any string argument automatically begins the 30-day trial. lnSuccess = loHtmlToXml.UnlockComponent("30-day trial") IF (lnSuccess <> 1) THEN =MESSAGEBOX("HtmlToXml component unlock failed") QUIT ENDIF * Indicate the charset of the output XML we'll want. loHtmlToXml.XmlCharset = "utf-8" * Set the HTML: loHtmlToXml.Html = lcHtml * We won't need the scripts or images, so drop those tags... loHtmlToXml.DropTagType("img") loHtmlToXml.DropTagType("script") * Get the XML: lcXmlStr = loHtmlToXml.ToXml() * Load the XML into the Chilkat XML parser: loXml = CreateObject('Chilkat.Xml') loXml.LoadXml(lcXmlStr) * 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" loNode = loXml.SearchForContent(NULL,"text","Chg From Prev Settle") IF (loNode = NULL ) THEN =MESSAGEBOX("Did not find Chg From Prev Settle") QUIT ENDIF * Move up to the TD node: loNode.GetParent2() * Move up to the TR node: loNode.GetParent2() * Move to the next row (i.e. next TR) loNode.NextSibling2() loNode.FirstChild2() loNode.NextSibling2() ? "Expire Month/Year: " + loNode.GetChildContent("text") loNode.NextSibling2() ? "Last: " + loNode.GetChildContent("text") loNode.NextSibling2() ? "Change: " + loNode.GetChildContent("text") loNode.NextSibling2() * ... lnSuccess = loNode.SaveXml("row.xml") RELEASE loNode |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2007 Chilkat Software, Inc. All Rights Reserved.
Mail Component · .NET Email Component · ASP Mail Component · XML Parser