获取英语每日一句(delphi)
时间:2010-12-14 来源:柳如士如柳
原理很简单, 先获取整个页面的信息, 由于是UTF-8字符, 所以需要转化一下.
然后通过查找关键字,将所要的句子截取出来.
//获取爱词霸每日一句 {uses IdHTTP}
function GetDayEnglish(): string;
var
reStr, str_1: string;
idhtp1: TIdHTTP;
begin
Result := '';
try
idhtp1 := TIdHTTP.Create(nil);
reStr := idhtp1.Get('http://www.iciba.com/');
reStr := Utf8ToAnsi(reStr);
str_1 := Copy(reStr,Pos('每日一句',reStr),300);
str_1 := Copy(str_1,Pos('onclick',str_1),300);
str_1 := Copy(str_1,Pos('">',str_1)+2,300);
Result := Copy(str_1, 1, Pos('</a>',str_1)-1);
except
FreeAndNil(idhtp1);
Result := 'Connect http://www.iciba.com/ ERROR!';
end;
if idhtp1 <> nil then FreeAndNil(idhtp1);
end;
当然根据这个原理, 你可以扩展去获取更多的信息.
1. 比如说本机的外网IP,可以通过这个网站http://www.ipseeker.cn;
2. 还有时间...