使用fiddle截获post给服务器的url和数据,使用httprequest类代码post到服务器
今天给出另外一种方法,就是利用winform控件中的webbrowser控件来操作页面。
这里我们会模拟一个搜索过程,打开百度网站,输入搜索关键字,在搜索结果中打开连接
代码如下 | 复制代码 |
public form1() { initializecomponent(); (webbrowser1.activexinstance as shdocvw.webbrowser).navigatecomplete2 += new shdocvw.dwebbrowserevents2_navigatecomplete2eventhandler(form1_navigatecomplete2); } void form1_navigatecomplete2(object pdisp, ref object url) { ihtmldocument2 doc = (webbrowser1.activexinstance as shdocvw.webbrowser).document as ihtmldocument2; doc.parentwindow.execscript("window.alert=null", "网页特效"); doc.parentwindow.execscript("window.confirm=null", "javascript"); doc.parentwindow.execscript("window.open=null", "javascript"); doc.parentwindow.execscript("window.showmodaldialog=null", "javascript"); doc.parentwindow.execscript("window.close=null", "javascript"); } |
代码写到这里已经提交搜索了,webbrowser也会接收这次提交后的记过,下面我们需要在结果中打开一个连接做实验。
先查看一下搜索结果的html源代码
代码如下 | 复制代码 |
private void webbrowser1_documentcompleted(object sender, webbrowserdocumentcompletedeventargs e) { htmldocument doc = this.webbrowser1.document; if(doc.url.absoluteuri=="http://www.baidu.com/") { doc.getelementbyid("kw").innertext = "翁玉礼"; doc.getelementbyid("su").invokemember("click"); } if(doc.url.absoluteuri.contains("wd"))//根据url中的 { htmlelement table = doc.getelementbyid("1");//根据搜索结果的html表,找到第一个搜索结果的url,这里模拟 var html = table.children[0].children[0].innerhtml; var url = html.substring(html.indexof("href") + 6, html.indexof(" target")); this.webbrowser1.navigate(url); } } |
敢达决战官方正版 安卓版v6.7.9
下载敢达决战 安卓版v6.7.9
下载像素火影骨架佐助 (Perseverance Fire Shadow)手机版v1.16
下载要塞英雄 安卓版v33.20.0-39082670-Android
下载梦想城镇vivo最新版本 安卓版v12.0.1
梦想城镇vivo版是这款卡通风模拟经营类手游的渠道服版本,玩
怦然心动的瞬间 安卓版v1.0
怦然心动的瞬间是一款真人向的恋爱互动游戏,在游戏中玩家将扮演
曼尼汉堡店游戏 安卓版v1.0.3
曼尼汉堡店是一款非常好玩的精品恐怖类型冒险游戏,在这款游戏中
现代总统模拟器去广告版 安卓版v1.0.46
现代总统模拟器是一款休闲养成类游戏,可能对于不少的玩家来说都
现代总统模拟器付费完整版 安卓版v1.0.46
现代总统模拟器高级版在商店是需要付费的,相对于普通版本,高级