如何编写从网页中读取所需要的数据?(0分)

  • 主题发起人 主题发起人 xysir001
  • 开始时间 开始时间
X

xysir001

Unregistered / Unconfirmed
GUEST, unregistred user!
如题。
谢谢!!!
 
procedure TForm1.Button3Click(Sender: TObject);
var
DoC: IHTMLDocument2;
begin
list:=TstringList.Create;
Doc := WebBrowser1.Document as IHTMLDocument2;
Memo1.Lines.Add(Doc.body.outerhtml); //读源码
Memo1.Lines.Add(Doc.body.outerText); //Html To Text
end;

需要引入
component/import activeX control ../microsoft html object library(version4.0).

再uses里 MSHTML_TLB

试试看吧
 
wqhatnet:
  我希望的是能从网页中读取所需要的数据,而不是将整个网页转为txt。
希望能有更好的解决办法!
 
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ScktComp, StdCtrls;

type
TForm1 = class(TForm)
ClientSocket: TClientSocket;
btnLink: TButton;
btnSend: TButton;
Memo: TMemo;
Edit: TEdit;
Button1: TButton;
procedure btnLinkClick(Sender: TObject);
procedure btnSendClick(Sender: TObject);
procedure ClientSocketRead(Sender: TObject; Socket: TCustomWinSocket);
procedure ClientSocketConnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}
Var
f:File;

procedure TForm1.btnLinkClick(Sender: TObject);
begin
AssignFile(f,'out.txt');
Rewrite(F,1);
Memo.Lines.Clear;
ClientSocket.Open;
end;

procedure TForm1.btnSendClick(Sender: TObject);
begin
ClientSocket.Socket.SendText('GET /'+Edit.Text+#$0A);
end;

procedure TForm1.ClientSocketRead(Sender: TObject;
Socket: TCustomWinSocket);
Var
s:String;
begin
If Socket.Connected Then
Begin
s:=Socket.ReceiveText;
Memo.Lines.Add(s);
BlockWrite(F,s[1],Length(s));
End;
end;

procedure TForm1.ClientSocketConnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
Memo.Lines.Add('AAAAAConn');
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
ClientSocket.Close;
CloseFile(f);
end;

end.


把数据从取得的网页里分离就不要我讲了吧。
 
楼主可能讲得不太详细,你是不是想得到网页中特定的某个控件,或者单元格的值
 
奇怪,你不先得到全部的数据,怎样从中搜索你想要的?
 
后退
顶部