获取英语每日一句(delphi)

调用下面这个函数,可以获取http://www.iciba.com/网站的英语每日一句.

原理很简单, 先获取整个页面的信息, 由于是UTF-8字符, 所以需要转化一下.

然后通过查找关键字,将所要的句子截取出来.

 

//获取爱词霸每日一句  {uses IdHTTP}
function TFrmTip.GetDayEnglish(): string;
var
  reStr, str_1: string;
  idhtp1: TIdHTTP;
begin
  Result := '';
  try
    idhtp1 := TIdHTTP.Create(nil);
    reStr := idhtp1.Get('http://news.iciba.com/dailysentence');
    reStr := Utf8ToAnsi(reStr);

    str_1 := Copy(reStr,Pos(FormatDateTime('YYYY-MM-DD', Now),reStr)+13,300);

    str_1 := Copy(str_1,1, Pos('。',str_1)-1);

    Result := str_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. 还有时间...

posted @ 2010-12-14 21:21  小阿枫  阅读(402)  评论(0编辑  收藏  举报