Delphi webbrowser 的一些方法
因为一个任务,最近几天一直在研究Webbrowser的相关功能,下面是收集到的一些方法
//根据URL获取请求Header
function GetAllHeaders(URL: string): string;
var
hSession: HInternet;
hURL: HInternet;
hReq: HInternet;
bRet: Boolean;
sBuff: String;
lBuffLen:DWord;
dwParam: DWord;
aResult: String;
aServer: string;
aFilePath: string;
I: Integer;
begin
Result := 'Unknown error';
aFilePath := URL;
if pos('http://', aFilePath) = 1 then
Delete(aFilePath, 1, 7);
aServer := SplitAtToken(aFilePath, '/');
dwParam := 0;
hSession := InternetOpen(
'http generic',
INTERNET_OPEN_TYPE_PRECONFIG, {use IE's setup to conect to the web}
nil, nil, 0);
try
if hSession = nil then
Exit; hURL := InternetConnect(hSession,
PChar(aServer), {the server we wants to conect to}
INTERNET_DEFAULT_HTTP_PORT, nil, nil,
INTERNET_SERVICE_HTTP, 0, 1);
try
if hURL = nil then
Exit; hReq := HttpOpenRequest(hURL,
nil, {nil defaults to the 'GET' verb}
PChar(aFilePath), {actual file on the server}
HTTP_VERSION, nil, nil,
INTERNET_FLAG_RELOAD, 0);
try
if hReq = nil then
Exit;
if not HttpSendRequest(hReq, nil, 0, 0, 0) then
Exit;
SetLength(sBuff, 1024); //set plenty of room in buffer
lBuffLen := Length(sBuff); bRet := HttpQueryInfo(hReq,
HTTP_QUERY_RAW_HEADERS_CRLF, {get all headers in one move}
@sBuff[1], lBuffLen, dwParam);
if bRet then
Result := sBuff
else
Result := 'QueryInfo error = '+IntToStr(GetLastError);
finally
InternetCloseHandle(hReq);
end;
finally
InternetCloseHandle(hURL);
end;
finally
InternetCloseHandle(hSession);
end;
end;
//获取 WebBrowser 控件当前显示页面的Html
function GetCompleteHTMLSource(wb: TWebBrowser) : string;
var
iDoc: IHTMLDocument2;
iall : IHTMLElement;
begin
Result := '';
if Assigned(wb.Document) then begin iDoc := wb.Document as IHTMLDocument2;
iall := iDoc.body; while iall.parentElement <> nil do begin
iall := iall.parentElement;
end; Result := iall.outerHTML;
end;
end;
Delphi webbrowser 的一些方法的更多相关文章
- delphi WebBrowser的使用方法详解(五)-难点释疑
网页代码:<SELECT id=fy onchange=TouchRefresh(1) name=fy> <OPTION selected value=15>每頁顯示15筆&l ...
- delphi WebBrowser的使用方法详解(六)
通篇引用mshtml; 一.webbrowser获取滚动条的位置 function GetScrollPositionX(FWB:TEmbeddedWB):Integer; //水平滚动条位置 ...
- delphi WebBrowser的使用方法详解(三)
WebBrowser 操作记要 WebBrowser1.GoHome; //到浏览器默认主页 WebBrowser1.Refresh; //刷新 WebBrowser1.GoBack; //后退 ...
- delphi WebBrowser的使用方法详解(四)-webbrowser轻松实现自动填表
webbrowser轻松实现自动填表 步骤如下: 第一步:获取网页 调用Webbrowser 的Navigate系列函数.等待网页装载完成,得到document对象. 在调用 webBrowser. ...
- delphi WebBrowser控件上网页验证码图片识别教程(一)
步骤一:获取网页中验证码图片的url地址 在delphi中加入一个BitBtn和一个memo以及WebBrowser控件实现网页中验证码图片的url地址的获取 程序如下:procedure TForm ...
- <总结>delphi WebBrowser控件的使用中出现的bug
Delphi WebBrowser控件的使用中出现的bug: 1.WebBrowser.Visible=false:Visible属性不能使WebBrowser控件不可见,暂时用 WebBrowse ...
- Delphi WebBrowser控件的使用(大全 good)
Delphi WebBrowser控件的使用 WebBrowser控件属性:1.Application 如果该对象有效,则返回掌管WebBrowser控件的应用程序实现的自动化对象(IDis ...
- Delphi之静态方法,虚方法virtual,动态dynamic,抽象abstract,消息
Delphi之静态方法,虚方法virtual,动态dynamic,抽象abstract,消息 http://www.cnblogs.com/zhwx/archive/2012/08/28/266055 ...
- [delphi]indy idhttp post方法
网易 博客 LOFTCam-用心创造滤镜 LOFTER-最美图片社交APP 送20张免费照片冲印 > 注册登录 加关注 techiepc的博客 万事如意 首页 日志 LOFTER 相册 音乐 ...
随机推荐
- [Z]用subcaption包排版子图(表)与图(表)格式设置
很不错的一篇文章,可以进一步参考caption和subcaption的文档: http://www.peteryu.ca/tutorials/publishing/latex_captions
- 在线浏览office 文件
http://blog.csdn.net/binyao02123202/article/details/20051683 [Asp.net]常见word,excel,ppt,pdf在线预览方案,有图有 ...
- Arduino UNO 键盘记录器中时钟接到2口或3口,其它接口不行。马上就要放弃了。要修改例子中时钟的引脚。
- Maven Profiles 定义不同环境的参数变量
应用场景 我们在开发的时候会遇到需要区分正式环境.测试环境.开发环境使用不同的参数,如数据库的用户名及密码等.这时可以用Spring 的PropertyPlaceholderConfigurer 来配 ...
- Spring cloud Eureka高可用 - 配置
个人项目源码: https://github.com/easonstudy/cloud-demo/tree/master/eureka-peer-server Window 7 修改hosts ht ...
- rtmp连接服务器失败(一个低级错误)
由于rtmp底层使用的也是socket ,所以如果想正常使用RTMP_Connect(); 则需要在使用该连接之前先初始化套接字: WORD wVersionRequested; WSADATA ws ...
- 利用maven实现差异化配置
回顾过去 生产环境,测试环境,开发环境在不同的环境下会有各种各样的配置,比如数据库链接地址,账户名,密码等等.不同环境下都需要配置,但是配置却又不同.以前分享过一篇文章,介绍了我之前A公司的差异化配置 ...
- effective javascript 学习心得
第2条:理解JavaScript的浮点数 1.js数字只有一种类型 2.见代码 /** * Created by Administrator on 2017/7/2. */ console.log(& ...
- C++提高编译与链接速度的资料
1,https://blog.csdn.net/lihao21/article/details/47610309 2,https://www.zhihu.com/question/37330979 3 ...
- 使用火狐浏览器访问双向认证的k8s api
首先 不能在火狐里对要访问的网址添加例外 打开 选项->高级->查看证书->证书机构->导入.先择服务端ca.crt后根据提示导入证书 生成p12文件 openssl pkcs ...