dll全部代码
unit PlugInUnit;
interface
uses Graphics, extdlgs, Windows, Classes, SysUtils;
type
TnewsInfo = record
title: string;
url: string;
newstime: Tdatetime;
content: string;
end;
function groupname: pchar;
//新闻类别名称
function groupurl: pchar;
//新闻地址
//function titlelist(body: string): TList;
//新闻标题列表
procedure titlelist(body: pchar;aList:bList);
//新闻标题列表
function content(body: string): pchar;
//新闻内容
function Html2Text(Str: string): string;
//html2text
implementation
function groupname: pchar;
//新闻类别名称
begin
Result := pchar('网易国内新闻');
end;
function groupurl: pchar;
//新闻地址
begin
Result := pchar('http://news.163.com/local.html');
end;
function Html2Text(Str: string): string;
var
StrL, i: Integer;
NewStr: string;
begin
StrL := StrLen(PChar(Str));
i := 0;
while i < StrL do
begin
Inc(i);
if Str = '>' then
begin
while Str[i + 1] <> '<' do
begin
Inc(i);
if i > StrL then
Break;
NewStr := NewStr + Str;
end;
//End While
end;
//End if
end;
//end While
Result := NewStr;
end;
//function titlelist(body: string): TList;
//新闻标题列表
procedure titlelist(body: pchar;aList:TList);
var
strtemp: string;
substr: string;
urlstr, urltemp: string;
title, temptitle, temptime: string;
newstime: Tdatetime;
MyInfo: ^TnewsInfo;
begin
//titlelist := TList.Create;
strtemp := StrPas(body);
while pos('<li>', strtemp) <> 0 do
begin
strtemp := copy(strtemp, pos('<li>', strtemp) + 4, length(strtemp) - pos('<li>', strtemp) - 4);
substr := copy(strtemp, 1, pos('</font>', strtemp) + 7);
//取出新闻内容页地址
if pos('href=', substr) <> 0 then
begin
urltemp := copy(substr, pos('href=', substr) + 5, length(substr) - pos('href=', substr) - 5);
urlstr := 'http://news.163.com' + copy(urltemp, 1, pos('target=_blank>', urltemp) - 2);
end;
//标题
title := Html2Text('<>' + substr);
title := StringReplace(title, '"', '', [rfReplaceAll]);
title := StringReplace(title, ')', ')', [rfReplaceAll]);
title := StringReplace(title, '(', '(', [rfReplaceAll]);
//时间 (07-15 13:38) --》2002-07-15 13:38
//取最好一对括号里的内容
temptitle := title;
while pos('(', temptitle) <> 0 do
begin
temptime := copy(temptitle, pos('(', temptitle) + 1, pos(')', temptitle) - pos('(', temptitle) - 1);
temptitle := copy(temptitle, pos(')', temptitle) + 1, length(temptitle) - pos(')', temptitle));
end;
try
newstime := strtodatetime(temptime);
except
newstime := now;
end;
if (title <> '') then
begin
New(MyInfo);
MyInfo^.title := title;
MyInfo^.url := urlstr;
MyInfo^.newstime := newstime;
alist.Add(MyInfo);
end;
end;
end;
function content(body: string): pchar;
//新闻内容
var
content: string;
begin
content := copy(body, pos('<!--start_1-->', body) + 14, pos('<!--end_1-->', body) - pos('<!--start_1-->', body) - 14);
if pos('<!--start_img-->', body) <> 0 then
content := '<center>' + copy(body, pos('<!--start_img-->', body) + 16, pos('<!--end_img-->', body) - pos('<!--start_img-->', body) - 16) + '</center><br>' + content;
Result := pchar(content);
end;
end.