PB取网页内容的方法

PB取网页内容的方法2009-03-08 07:41以前以为PB不能做此类程序,今天在网上看到,赶紧收起来转发到BLOG上,以后可能用得上string ls_get_url, ls_args 
string ls_response_text, ls_status_text 
long ll_status_code 
long ps1, ps2, ps3, ps4 
string srstr1, srstr2 
n_cst_string lhv_string 
OleObject loo_xmlhttp 
string ls_nj, ls_deptno, ls_deptname, ls_spenme, ls_temp1, ls_temp2, ls_temp3 
long isel_total=0, row, row_spe, lii, lij, li_rs, li_rsdet

ls_nj = trim(ddlb_1.text) 
if ls_nj='' then 
messageboxx('提示','请先选择年级!', Information!, OK!, 1) 
return 
end if 
if dw_dept.rowcount() <=0 then return

ls_get_url = "http://" + trim(sle_1.text)+"/newcsu/common/search/classresult1.aspx"

dw_special.reset()

for row=1 to dw_dept.rowcount() 
if dw_dept.getitemnumber(row,'isel')=1 then 
isel_total++ 
ls_deptno = trim(dw_dept.getitemstring(row,'院系代码')) 
ls_deptname = trim(dw_dept.getitemstring(row,'院系名称')) 
//ls_args = "grade=06级%20&deptId=03%20&deptName=资源加工与生物工程学院" 
ls_args = "grade="+ls_nj+"%20&deptId="+ls_deptno+"%20&deptName="+ls_deptname

try 
loo_xmlhttp = CREATE oleobject 
loo_xmlhttp.ConnectToNewObject("Msxml2.XMLHTTP.4.0") 
loo_xmlhttp.open ("GET",ls_get_url + "?" + ls_args, false) 
loo_xmlhttp.send() 
//Get our response 
ls_status_text = loo_xmlhttp.StatusText 
ll_status_code = loo_xmlhttp.Status 
//Check HTTP Response code for errors 
if ll_status_code >= 300 then 
messageboxx('提示','Web的GET请求失败!~r~n~r~n'+ls_response_text, Information!, OK!, 1) 
else 
//Get the response we received from the web server 
ls_response_text = loo_xmlhttp.ResponseText 
end if

srstr1 = ls_response_text 
srstr2 = '~t </tr> <tr style="color:#003399;background-color:White;">~r~n~t~t <td align="Center">' 
ps1 = pos(ls_response_text, srstr2, 1) 
if ps1=0 then continue 
srstr1 = mid(ls_response_text, ps1+len(srstr2)) 
srstr1 = lhv_string.of_globalreplace(srstr1,srstr2, '') 
srstr1 = lhv_string.of_globalreplace(srstr1,' </td> <td align="Center">', '~t') 
srstr1 = lhv_string.of_globalreplace(srstr1,' </td> <td>', '~t') 
srstr1 = lhv_string.of_globalreplace(srstr1,' </td>', '') 
srstr1 = lhv_string.of_globalreplace(srstr1,'~t </tr>~r~n </table>~r~n~t~t~t </form>~r~n~t </body>~r~n </HTML>~r~n','') 
//mle_1.text = srstr1

//Done so cleanup 
loo_xmlhttp.DisconnectObject()

li_rs = long( f_fj_str(srstr1,'~r~n',0)) 
for lii=1 to li_rs 
ls_temp1 = f_fj_str(srstr1,'~r~n',lii ) 
ls_temp2 = f_fj_str(ls_temp1, '~t', 1 ) 
ls_spenme = ls_temp2 
ls_temp2 = f_fj_str(ls_temp1, '~t', 3 ) 
ls_temp2 = mid(ls_temp2,2) + '/' 
li_rsdet = long(f_fj_str(ls_temp2,'/',0)) 
for lij=1 to li_rsdet 
ls_temp3 = trim (f_fj_str(ls_temp2,'/',lij)) 
row_spe = dw_special.insertrow(0) 
dw_special.setitem(row_spe,'isel', 1) 
dw_special.setitem(row_spe,'zy', ls_spenme) 
dw_special.setitem(row_spe,'bj', ls_temp3) 
dw_special.setitem(row_spe,'yx', ls_deptname) 
next 
next 
if dw_special.rowcount()>0 then 
cb_getxs.enabled = true 
else 
cb_getxs.enabled = false 
end if

catch (RuntimeError rte) 
messageboxx('运行时错', rte.getMessage(), Information!, OK!, 1) 
return 
end try

end if 
next

if isel_total=0 then 
messageboxx('提示','请先选择院系!', Information!, OK!, 1) 
return 
end if 
---------

另外一种:

forward 
global type w_maintain_preview from window 
end type 
type ole_web from olecustomcontrol within w_maintain_preview 
end type 
type cb_back from commandbutton within w_maintain_preview 
end type 
end forward

global type w_maintain_preview from window 
integer width = 1650 
integer height = 980 
boolean titlebar = true 
string title = "维修企业权限分配" 
boolean controlmenu = true 
boolean minbox = true 
boolean maxbox = true 
boolean resizable = true 
windowstate windowstate = maximized! 
long backcolor = 67108864 
string icon = "AppIcon!" 
boolean center = true 
ole_web ole_web 
cb_back cb_back 
end type 
global w_maintain_preview w_maintain_preview

type variables

private: 
string is_logName,is_passwd 
boolean ib_loginDocument = true 
boolean lb_true=true 
end variables

event open;string ls_localIP 
ls_localIP = message.stringparm

//ole_web.object.navigate(ls_localIP) 
//setnull(ls_localIP)

//messagebox("ip","ewee") 
select loginName,magcard into :is_logName,:is_passwd from lt_operator where id = :gl_operatorID ;

ole_web.object.navigate(ls_localIP)

end event

on w_maintain_preview.create 
this.ole_web=create ole_web 
this.cb_back=create cb_back 
this.Control[]={this.ole_web,& 
this.cb_back} 
end on

on w_maintain_preview.destroy 
destroy(this.ole_web) 
destroy(this.cb_back) 
end on

event resize; 
long ll_space = 20

setRedraw(false)

ole_web.move(0,0) 
ole_web.width = workspaceWidth() - 1 
ole_web.height = workspaceHeight() - cb_back.height - 2*ll_space 
ole_web.object.top = 0 
ole_web.object.left = 0 
ole_web.object.width = UnitsToPixels(workspaceWidth() - 1,XUnitsToPixels!) 
ole_web.object.height = UnitsToPixels(workspaceHeight() - cb_back.height - 2*ll_space,YUnitsToPixels!)

cb_back.move(workspaceWidth() - ll_space - cb_back.width,workspaceHeight() - ll_space - cb_back.height)

setRedraw(true) 
end event

type ole_web from olecustomcontrol within w_maintain_preview 
event statustextchange ( string text ) 
event progresschange ( long progress,  long progressmax ) 
event commandstatechange ( long command,  boolean enable ) 
event downloadbegin ( ) 
event downloadcomplete ( ) 
event titlechange ( string text ) 
event propertychange ( string szproperty ) 
event beforenavigate2 ( oleobject pdisp,  any url,  any flags,  any targetframename,  any postdata,  any headers,  ref boolean cancel ) 
event newwindow2 ( ref oleobject ppdisp,  ref boolean cancel ) 
event navigatecomplete2 ( oleobject pdisp,  any url ) 
event documentcomplete ( oleobject pdisp,  any url ) 
event onquit ( ) 
event onvisible ( boolean ocx_visible ) 
event ontoolbar ( boolean toolbar ) 
event onmenubar ( boolean menubar ) 
event onstatusbar ( boolean statusbar ) 
event onfullscreen ( boolean fullscreen ) 
event ontheatermode ( boolean theatermode ) 
event windowsetresizable ( boolean resizable ) 
event windowsetleft ( long left ) 
event windowsettop ( long top ) 
event windowsetwidth ( long ocx_width ) 
event windowsetheight ( long ocx_height ) 
event windowclosing ( boolean ischildwindow,  ref boolean cancel ) 
event clienttohostwindow ( ref long cx,  ref long cy ) 
event setsecurelockicon ( long securelockicon ) 
event filedownload ( ref boolean cancel ) 
event navigateerror ( oleobject pdisp,  any url,  any frame,  any statuscode,  ref boolean cancel ) 
event printtemplateinstantiation ( oleobject pdisp ) 
event printtemplateteardown ( oleobject pdisp ) 
event updatepagestatus ( oleobject pdisp,  any npage,  any fdone ) 
event privacyimpactedstatechange ( boolean bimpacted ) 
integer width = 1467 
integer height = 560 
integer taborder = 10 
boolean border = false 
borderstyle borderstyle = stylelowered! 
boolean focusrectangle = false 
string binarykey = "w_maintain_preview.win" 
integer textsize = -10 
integer weight = 400 
fontcharset fontcharset = gb2312charset! 
fontpitch fontpitch = variable! 
string facename = "宋体" 
long textcolor = 33554432 
end type

event downloadcomplete(); 
//messagebox('',isnull(rte_1.object.Document))

end event

event documentcomplete(oleobject pdisp, any url); 
if lb_true then 
ole_web.object.document.form1.txtUser.innerText =is_logName 
ole_web.object.document.form1.txtPassed.innerText =is_passwd 
ole_web.object.document.form1.btnOk.click() 
lb_true =false 
end if 
end event

type cb_back from commandbutton within w_maintain_preview 
integer x = 1152 
integer y = 680 
integer width = 320 
integer height = 100 
integer taborder = 20 
integer textsize = -12 
integer weight = 400 
fontcharset fontcharset = gb2312charset! 
fontpitch fontpitch = variable! 
string facename = "宋体" 
string text = "返回(&B)" 
end type

event clicked; 
close(parent) 
end event

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值