idhttp与Webbrowser共享Cookie

该日志由 samool 发表于 2013-02-03 12:35:51

让idhttp与浏览器共享Cookie信息,这样只要浏览器登录以后,idhttp就不用登录了,抓取数据包神马的就是浮云了。

uses
..., WinInet;


function CanGetIECookie(const URL: string; var Cookie: string): boolean;
var
lpvBuffer: array[0..1000] of byte;
lpdwBufferLength: cardinal;
begin
lpdwBufferLength := sizeof(lpvBuffer);
result := InternetGetCookie(PChar(URL), nil, @lpvBuffer, lpdwBufferLength);
if result then
Cookie := pchar(@lpvBuffer);
end;


if CanGetIECookie(url, str) then
begin
CookieStr := 'Cookie: ' + str;
idHttp1.Request.CustomHeaders.Text := CookieStr;
Memo1.Lines.Text := IdHTTP1.Get(WebSite);
end;

该日志标签: webbrowser, cookie, idhttp

WebBrowser 提取html源码

该日志由 samool 发表于 2013-01-31 15:49:06

[delphi WebBrowser] WebBrowser 提取html源码

uses mshtml;

procedure TForm1.wb1DocumentComplete(Sender: TObject; const pDisp: IDispatch; var URL: OleVariant);
var
i:Integer;
iall : IHTMLElement;
begin
if wb1.Application = pDisp then
begin
mmo1.Clear;
if Assigned(wb1.Document) then
begin
iall := (wb1.Document AS IHTMLDocument2).body;
while iall.parentElement <> nil do
begin
iall := iall.parentElement;
end;
mmo1.Text := mmo1.Text+iall.outerHTML;
end;
end;
end;

该日志标签: delphi, webbrowser

delphi中webBrowser控件滚动条自动滚动

该日志由 samool 发表于 2012-12-27 14:01:07

uses mshtml;

var    htmldoc: IHTMLDocument2;
      MaxScrollWidth, MaxScrollHeight: Integer;

htmldoc := web.Document as IHTMLDocument2;
MaxScrollHeight := htmldoc.body.getAttribute('ScrollHeight', 0);  //获得滚动条最大高度
MaxScrollWidth := htmldoc.body.getAttribute('ScrollWidth', 0);//获得滚动条最大宽度
Web.OleObject.Document.ParentWindow.ScrollBy(MaxScrollWidth, MaxScrollHeight ); //滚动到最右最下

 

该日志标签: webbrowser, 滚动条

让TwebBrowser也能响应回车键

该日志由 samool 发表于 2008-03-14 10:17:15

delphi 中 webbrowser1 浏览器中浏览网页,输入文本不能用ENTER键,无论你怎么按ENTER键,它都不会换行,还有,右键菜单的复制,和粘贴根本不是那么一回事,为什么呢?为什么??答案很简单,因为webbrowser不支持回车键响应,必须加上代码才行。

以下方法经本人测试通过,操作系统为XP sp2,开发环境Delphi7,浏览器是IE7.

1,在使用TwebBrowser控件的窗体(例如MainForm)中创建一个函数(代码里的wb对应你的webbrowser名称)
procedure TfrmMain.MsgHandler(var Msg: TMsg; var Handled: Boolean);
var
iOIPAO: IOleInPlaceActiveObject;
Dispatch: IDispatch;
begin

{ exit if we don't get back a webbrowser object }
if (wb = nil) then
begin
Handled := False;
Exit;
end;

Handled := (IsDialogMessage(wb.Handle, Msg) = True);
if (Handled) and (not wb.Busy) then
begin
if FOleInPlaceActiveObject = nil then
begin
Dispatch := wb.Application;
if Dispatch <> nil then
begin
Dispatch.QueryInterface(IOleInPlaceActiveObject, iOIPAO);
if iOIPAO <> nil then
FOleInPlaceActiveObject := iOIPAO;
end;
end;

if FOleInPlaceActiveObject <> nil then
if ((Msg.message = WM_KEYDOWN) or (Msg.message = WM_KEYUP)) and
((Msg.wParam = VK_BACK) or (Msg.wParam = VK_LEFT) or (Msg.wParam =
VK_RIGHT)) then
//nothing - do not pass on Backspace, Left or Right arrows
else
FOleInPlaceActiveObject.TranslateAccelerator(Msg);
end;
end;

procedure TForm1.FormDeactivate(Sender: TObject);
begin
Application.OnMessage := oldHandler;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Application.OnMessage := oldHandler;
FOleInPlaceActiveObject := nil;
end;

2,在该窗体的FormCreate事件中,添加以下代码
oldHandler := Application.OnMessage;
Application.OnMessage := MsgHandler;

3,在该Form的private中声明以下两个全局变量
FOleInPlaceActiveObject: IOleInPlaceActiveObject;
oldHandler: TMessageEvent

4,把activeX头文件包进去

该日志标签: webbrowser, 回车, enter

设置WebBrowser的Referrer值

该日志由 samool 发表于 2007-07-19 00:09:13

有些网站为防止外站注入,增加了网址的来源检测,一般就是检查浏览器的Referrer值是否为本站,如果Referrer的网址不是本站地址,就认为不是全法进入的。如果在程序中用WebBrowser来实现自动进入某网站的某一页面呢? 这就必须设置WebBrowser的Referrer值,WebBrowser.doc2.Referrer 又是只读属性,是没有办法直接设置URL的,不像idhttp可以直接指定headers或者用Request.Referrer,我们可以用下面方法轻松实现设置WebBrowser的Referrer值。

方法如下:
wb1.Navigate('https://samool.com/');
wb1.Navigate('https://samool.com/1.html');

.com/1.html');

该日志标签: webbrowser, 浏览器, referrer, 来源, seo

WebBrowser控件实现对IE浏览器的各种控制

该日志由 samool 发表于 2007-06-08 15:51:14

WebBrowser控件实现对IE浏览器的各种控制

在不是js打开的页面上按window.close(),会有提示框,很烦,现在可以不用了,没有提示框直接关闭窗口。

试试下面代码:

<object id="WebBrowser" width=0 height=0 classid="CLSID:8856F961_340A_11D0_A96B_00C04FD705A2">
</object>
<input type="button" name="Button" value="关闭窗口" onClick="document.all.WebBrowser.ExecWB(45,1)">

试着改变参数会得到其他一些功能:

WebBrowser.ExecWB(1,1) 打开
WebBrowser.ExecWB(2,1) 关闭现在所有的IE窗口,并打开一个新窗口
WebBrowser.ExecWB(4,1) 保存网页
WebBrowser.ExecWB(6,1) 打印
WebBrowser.ExecWB(7,1) 打印预览
WebBrowser.ExecWB(8,1) 打印页面设置
WebBrowser.ExecWB(10,1) 查看页面属性
WebBrowser.ExecWB(15,1) 好像是撤销,有待确认
WebBrowser.ExecWB(17,1) 全选
WebBrowser.ExecWB(22,1) 刷新
WebBrowser.ExecWB(45,1) 关闭窗体无提示

这些只对IE5.5以上版本有效,我是在IE6下测试的,通过的。

代码:

--------------------------------------------------------------------------------

■打开■
<input name=Button onClick=document.all.WebBrowser.ExecWB(1,1) type=button value=打开>
<OBJECT classid=CLSID:8856F961_340A_11D0_A96B_00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT>
■另存为■
<input name=Button onClick=document.all.WebBrowser.ExecWB(4,1) type=button value=另存为><OBJECT classid=CLSID:8856F961_340A_11D0_A96B_00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT>
■属性■
<input name=Button onClick=document.all.WebBrowser.ExecWB(10,1) type=button value=属性><OBJECT classid=CLSID:8856F961_340A_11D0_A96B_00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT>
■打印■
<input name=Button onClick=document.all.WebBrowser.ExecWB(6,1) type=button value=打印><OBJECT classid=CLSID:8856F961_340A_11D0_A96B_00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT>
■页面设置■
<input name=Button onClick=document.all.WebBrowser.ExecWB(8,1) type=button value=页面设置><OBJECT classid=CLSID:8856F961_340A_11D0_A96B_00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT>
■刷新■
<input type=button value=刷新 name=refresh onclick="window.location.reload()">
■导入收藏■
<input type="button" name="Button" value="导入收藏夹" onClick=window.external.ImportExportFavorites(true,);>
■导出收藏■
<input type="button" name="Button3" value="导出收藏夹" onClick=window.external.ImportExportFavorites(false,);>
■加入收藏■
<INPUT name=Button2 onclick="window.external.AddFavorite(location.href, document.title)" type=button value=加入收藏夹>
■整理收藏夹■
<INPUT name=Submit2 onclick="window.external.ShowBrowserUI(OrganizeFavorites, null)" type=button value=整理收藏夹>
■查看原文件■
<INPUT name=Button onclick=window.location = "view-source:" + window.location.href type=button value=查看源文件>
■语言设置■
<INPUT name=Button onclick="window.external.ShowBrowserUI(LanguageDialog, null)" type=button value=语言设置>
■前进■
<INPUT name=Submit onclick=history.go(1) type=submit value=前进>
■后退■
<INPUT name=Submit2 onclick=history.go(-1) type=submit value=后退>

文章来源: http://zgqynx.javaeye.com/blog/66501

该日志标签: 控件, webbrowser, 浏览器