Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
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. uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, CHILKATXMLLib_TLB, HTMLTOXMLLib_TLB, CHILKATHTTPLib_TLB, OleCtrls; ... procedure TForm1.Button1Click(Sender: TObject); var http: TChilkatHttp; success: Integer; html: String; htmlToXml: THtmlToXml; xmlStr: String; xml: CHILKATXMLLib_TLB.IChilkatXml; node: CHILKATXMLLib_TLB.IChilkatXml; begin http := TChilkatHttp.Create(Self); // Any string unlocks the component for the 1st 30-days. success := http.UnlockComponent('Anything for 30-day trial'); if (success <> 1) then begin ShowMessage(http.LastErrorText); end; // 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: htmlToXml := THtmlToXml.Create(Self); // Any string argument automatically begins the 30-day trial. success := htmlToXml.UnlockComponent('30-day trial'); if (success <> 1) then begin ShowMessage('HtmlToXml component unlock failed'); end; // 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: xml := TChilkatXml.Create(Self).ControlInterface; 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" node := xml.SearchForContent(nil,'text','Chg From Prev Settle'); if (node = nil ) then begin ShowMessage('Did not find Chg From Prev Settle'); end; // 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(); Memo1.Lines.Add('Expire Month/Year: ' + node.GetChildContent('text')); node.NextSibling2(); Memo1.Lines.Add('Last: ' + node.GetChildContent('text')); node.NextSibling2(); Memo1.Lines.Add('Change: ' + node.GetChildContent('text')); node.NextSibling2(); // ... success := node.SaveXml('row.xml'); end; |
© 2000-2010 Chilkat Software, Inc. All Rights Reserved.