获取网页快照

简介: unit uWebCracker; interface uses mshtml,SHdocvw,classes,SysUtils,StrUtils; const MAXPAGECOUNT=20; type TWebPageRecord=record URL:string; Titl...

unit uWebCracker;

interface

uses mshtml,SHdocvw,classes,SysUtils,StrUtils;

const

MAXPAGECOUNT=20;

type

TWebPageRecord=record

URL:string;

Title:string;

Text:string;

end;

type

TWebCracker=class(TObject)

private

FWebPageRecordArray:array[0..MAXPAGECOUNT-1] of TWebPageRecord;

FWebPageCount:integer;

public

constructor Create;

destructor Free;

procedure SnapShot;

function GetWebText(AIndex:integer):string;

function GetWebTitle(AIndex:integer):sttring;

function GetWebURL(AIndex:integer):string;

procedure Clear;

procedure Refresh;

function GetWebPageCount:integer;

end;

implementation

constructor TWebCracker.Create;

begin

inherited Create;

FWebPageCount:=0;

end;

destructor TWebCracker.Free;

begin

clear;

inherited Free;

end;

procedure TWebCracker.SnapShot;

const

ERRORNOTLOADCOMPLETE='可能打开的网页还没有完全加载,请当所有的网页下载完后再刷新!'

var

ShellWindow:IShellWindow;

WebBrowser:IWebBrower2;

I,ShellWindowCount:integer;

HTMLDocument:IHTMLDocument2;

URL:string;

WebPageRecord:TWebPageRecord;

begin

FWebPageCount :=0;

ShellWindow:=CoShellWindow.Create;

ShellWindowCount :=ShellWindow.Create;

if ShellWindowCount>MAXPAGECOUNT then

ShellWindowCount:=MAXPAGECOUNT;

for i:=0 to ShellWindowCount-1 do

begin

WebBrowser:=ShellWindow.Item(I) as IWebBrowser2;

URL:=WebBrowser.LocationURL;

if (WebBrowser<>nil) and (not IsLocationFile(URL)) then

begin

try

HTMLDocument :=WebBrowser.Document as IHTMLDocument2;

WebPageRecord.URL :=URL;

WebPageRecord.Title :=HTMLDocument.title;

WebPageRecord.Text :=HTMLDocument.body.outerText;

FWebPageRecordArray[I] :=WebPageRecord;

Inc(FWebPageCount);

except

on Exception do

raise Exception.Create(ERRORNOTLOADCOMPLETE);

end;

end;

ShellWindow :=nil;

end;

end;

function TWebCracker.GetWebText(AIndex:integer):string;

begin

Result :=FWebPageRecordArray[AIndex].Text;

end;

function TWebCracker.GetWebTitle(AIndex:integer):string;

begin

Result :=FWebPageRecordArray[AIndex].Title;

end;

function TWebCracker.GetWebURL(AIndex:integer):string;

begin

Result :=FWebPageRecordArray[AIndex].URL;

end;

procedureTWebCracker.Clear;

begin

FWebPageCount :=0;

end;

procedureTWebCracker.Refresh;

begin

self.Snapshot;

end;

functionTWebCracker.GetWebPageCount:integer;

begin

Result :=FWebPageCount;

end;

相关文章
lda模型和bert模型的文本主题情感分类实战
lda模型和bert模型的文本主题情感分类实战
442 0
|
7月前
|
人工智能 机器人 开发工具
Amazon Nova Act:网页操作全自动!亚马逊黑科技把浏览器变AI机器人,请假/订餐/写邮件一键搞定
Amazon Nova Act是亚马逊AGI实验室推出的通用AI代理系统,通过原子化分解网页操作任务并配合Playwright实现高可靠性浏览器自动化,其配套SDK支持开发者快速构建智能体应用原型。
356 13
Amazon Nova Act:网页操作全自动!亚马逊黑科技把浏览器变AI机器人,请假/订餐/写邮件一键搞定
|
运维 监控 Java
|
iOS开发
我给 iOS 系统打了个补丁——修复 iOS 16 系统键盘重大 Crash(下)
我给 iOS 系统打了个补丁——修复 iOS 16 系统键盘重大 Crash(下)
780 1
|
分布式计算 算法 Java
阿里云ODPS PySpark任务使用mmlspark/synapseml运行LightGBM进行Boosting算法的高效训练与推理
阿里云ODPS PySpark任务使用mmlspark/synapseml运行LightGBM进行Boosting算法的高效训练与推理
1217 3
|
消息中间件 Java BI
使用Java和Spring Batch实现批处理
使用Java和Spring Batch实现批处理
|
安全 Java 数据安全/隐私保护
代码混淆技术探究与工具选择
在软件开发中,保护程序代码的安全性是至关重要的一环。代码混淆(Obfuscated code)作为一种常见的保护手段,通过将代码转换成难以理解的形式来提升应用被逆向破解的难度。本文将介绍代码混淆的概念、方法以及常见的代码混淆工具。
|
数据采集 存储 人工智能
【AI大模型应用开发】【LangChain系列】实战案例2:通过URL加载网页内容 - LangChain对爬虫功能的封装
【AI大模型应用开发】【LangChain系列】实战案例2:通过URL加载网页内容 - LangChain对爬虫功能的封装
854 0
|
存储 监控 大数据
【Elasticsearch专栏 15】深入探索:Elasticsearch使用API删除旧数据
本文探讨了如何使用Elasticsearch API管理并删除旧数据。Elasticsearch提供RESTful API,支持按条件批量删除。删除策略可基于时间、文档数量或索引。通过`DELETE BY QUERY` API,可以根据时间戳范围删除数据,如删除早于30天的记录。为处理大量数据,建议分批次进行,使用`scroll`和`size`参数控制。监控删除进度可使用任务ID。合理运用这些方法能有效优化存储,适应不同业务需求。
414 0