读书人

C# mshtml 兑现模拟点击a标签

发布时间: 2013-05-02 09:39:29 作者: rapoo

C# mshtml 实现模拟点击a标签

<IFRAME style="DISPLAY: none" src="about:blank"></IFRAME>
<DIV class=search_container>
<DIV class=search_input><INPUT tabIndex=1 id=search_input class=yahei maxLength=50 type=input> <SPAN onclick="$('search_input').focus();return false;" id=search_tips onselectstart="return false;" style="DISPLAY: block">请输入群号、关键词,多关键词间用空格隔开</SPAN> </DIV><A tabIndex=2 id=search_btn class=search_btn hideFocus href="javascript:void(0)">查找</A>
<DIV class=search_hot style="DISPLAY: none">热门搜索: <A href="javascript:void(0)">同城</A>  <A href="javascript:void(0)">旅游</A></DIV>
<DIV id=tips class=tips>请输入群号或关键词再点击查找</DIV>
<UL id=search_auto class=search_auto style="DISPLAY: none">
<LI><A class=select hideFocus href="#">英雄联盟</A> </LI></UL></DIV>
<DIV id=content>
<DIV class=group_think style="MARGIN-TOP: 10px">
<H2>您可能感兴趣的群</H2><A id=change_btn class=change hideFocus style="DISPLAY: inline-block" href="javascript:void(0)">换一批</A>
<UL id=content_recommend style="VISIBILITY: visible">
<LI id=li_48715864 style="ZOOM: 1" data-gc="48715864">
<DIV class=ie-bg></DIV><A onclick="Evts.delRecom(this);return false;" class=cls href="http://qqun.qq.com/search/index.html?keyword=#"></A><A class=head hideFocus href="javascript:void(0)"><IMG onerror=HeadError(this) id=head_48715864 src="http://3.url.cn/qun/search/img/head.png"></A>
<P><A id=name_48715864 title=长春龟友群 class=name hideFocus href="javascript:void(0)">长春龟友群</A><BR><B title=生活休闲-宠物>生活休闲-宠物</B><BR><SPAN title=喜欢龟龟的都来聊聊吧!>喜欢龟龟的都来聊聊吧!</SPAN> </P><A id=report_48715864 class=report hideFocus href="javascript:void(0)">举报</A>
<DIV class=tool><SPAN>68 人</SPAN> <A id=add_48715864 class=add hideFocus href="javascript:void(0)">加入</A> </DIV>
<DIV class=hot></DIV></LI>

</SCRIPT>

mshtml 如何实现模拟点击加群。

   /// <summary>
/// 输入群号码
/// </summary>
/// <param name="hWnd"></param>
/// <param name="Values"></param>
/// <returns></returns>
public bool Setvalue(IntPtr hWnd, string Values)
{
try
{
IHTMLDocument2 htmlDoc = GetHtmlDocument(hWnd);
if (htmlDoc != null)
{

mshtml.IHTMLElementCollection inputs;


inputs = (mshtml.IHTMLElementCollection)htmlDoc.all.tags("INPUT");
mshtml.IHTMLElement element = (mshtml.IHTMLElement)inputs.item("search_input", 0);
mshtml.IHTMLInputElement inputElement = (mshtml.IHTMLInputElement)element;
inputElement.value = Values;

return true;

}
else
{
return false;
}
}
catch (Exception ex)
{
common.LogManager.WriteLog(common.LogFile.Trace, "添加群号失败" + ex.ToString());
return false;
}
}


这是输入群号的地方 已经实现如何实现 执行<A id=add_48715864 class=add hideFocus href="javascript:void(0)">加入</A> C# mshtml
[解决办法]

可以模拟执行javascript吧
.InvokeScript("getPwd", new object[] { "18780110000" })
[解决办法]
如果你使用的是.NET Framework 2.0及其以上版本的话,可以利用WebBrowser控件提供的GetElementById方法

this.WebBrowser.GetElementById("Hyper Link Id").Click();

读书人网 >C#

热点推荐