今天在用python调用IE获取html网页元素在屏幕上的坐标,当然为了截图啦,(*^__^*) 嘻嘻……
xtop=ie.document.forms[i].elements[j].getBoundingClientRect().top + ie.document.parentwindow.screentop
xleft=ie.document.forms[i].elements[j].getBoundingClientRect().left + ie.document.parentwindow.screenleft
xwidth= ie.document.forms[i].elements[j].getBoundingClientRect().right - ie.document.forms[i].elements[j].getBoundingClientRect().left
xheight= ie.document.forms[i].elements[j].getBoundingClientRect().bottom - ie.document.forms[i].elements[j].getBoundingClientRect().top
forms[i].elements[j].可以用 getElementById(“username”) 代替
然后用python调用delphi截图程序,这样就可以获取网页元素上的截图了,有什么用,嘻嘻,获取图形验证码嘛,然后…
delphi的截图函数:
procedure tform1.snapscreen(a,b,c,d:Integer);
var
bmpscreen:Tbitmap;
jpegscreen:Tjpegimage;
FullscreenCanvas:TCanvas;
dc:HDC;
sourceRect, destRect: TRect;
begin
try
dc:=getdc(0);
fullscreencanvas:=Tcanvas.Create;
fullscreencanvas.Handle:=dc;
bmpscreen:=Tbitmap.create;
bmpscreen.Width :=c-a;
bmpscreen.Height :=d-b;
sourcerect:=rect(0,0,c-a ,d-b );
destrect:= rect(a,b,c,d);
bmpscreen.Canvas.CopyRect(sourcerect,fullscreenCanvas,destrect);
jpegscreen:=Tjpegimage.Create ;
jpegscreen.Assign (bmpscreen);
pressionQuality:=100;
jpegscreen.SaveToFile(ExtractFilePath(ParamStr(0))+'tmp.jpg');
FullscreenCanvas.Free;
bmpscreen.Free;
jpegscreen.Free ;
ReleaseDC(0, DC);
except
end;
end;
python调用exe:
os.system(‘jietu.exe ‘+str(xleft+3)+’ ‘+str(xtop+3)+’ ‘+str(xwidth)+’ ‘+str(xheight))
str(xleft+3)等是我的参数,大家应该看得明吧,(*^__^*) 嘻嘻……