delphi 读取全网站链接


本文整理自网络,侵删。

 function Ge_tLinks(Url: string): Tstrings;
var
HttpStr, str, Url1: string;
st1, end1, i, j, Ord1: integer;
begin
Result := TStringList.create; //创建Tstringlist事例

Httpstr := UrlGetStr(url);


for i := length(url) downto 9 do
begin
if url[i] = '/' then
begin
Url1 := copy(url, 1, i);
break;
end;
if i = 9 then Url1 := url + '/'; //结束都没有找到"/"就加一个"/"
end;

i := 1;
while true do
begin

st1 := Q_PosText('<a', httpstr, i);
st1 := Q_PosText('href=', httpstr, st1);

if (st1 = 0) or (st1 < i) then break;

st1 := st1 + 5; //开始位置设置为 href= 之后的位置
i := st1;

while true do
begin
// if i >= length(Httpstr) then break;
Ord1 := Ord(Httpstr[i]);
case Ord1 of
34, 39: //如果连接前有" 或 ' 就
begin
if i = st1 then
begin
st1 := st1 + 1;
end
else begin
end1 := i;
break;
end;
end;
36..38, 40..59, 61, 63..95, 97..254: ;
else
begin
end1 := i;
break;
end
end;
i := i + 1;
end;


//连接内容
str := copy(httpstr, st1, end1 - st1);

if (length(str) > 8) and (Q_PosText('mailto:', str, 1) = 0) and (Q_PosText('javascript:', str, 1) = 0) then
begin
if pos('://', str) = 0 then //表示要加前面网址的
begin
if str[1] = '/' then
begin
str := copy(url1, 1, Q_PosText('/', url1, 9)) + copy(str, 2, 100);
if Result.IndexOf(str) = -1 then Result.Add(str);
end
else begin
str := Url1 + str;
if Result.IndexOf(str) = -1 then Result.Add(str);
end;
end
else begin //表示本身就加了 http://的
if Result.IndexOf(str) = -1 then Result.Add(str);
end;
end;
i := end1; //
end;
end;

相关阅读 >>

Delphi 内存修改的实现

Delphi 防止系统睡眠

Delphi shutdown() 关机

Delphi xe andriod 文件后缀对应mime类型

Delphi bmp 转换jpg

Delphi hextoint32

Delphi 双击隐藏tabsheet

Delphi 16 进制转换为 10进制

Delphi命令行窗口实现9*9乘法表

Delphi 百度输入提示 Delphi 实现

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...