关于网友提出的“ 模拟论坛发贴!!有个问题严重困饶我。。高人来啊”问题疑问,本网通过在网上对“ 模拟论坛发贴!!有个问题严重困饶我。。高人来啊”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:
问题: 模拟论坛发贴!!有个问题严重困饶我。。高人来啊
描述: 我自己写了个程序。目的是用来在自己的Discuz论坛回贴和发贴
在程序中嵌入了一个浏览器控件m_Web用来打开网页。
首先是在这个浏览器打开我的论坛然后用ID登陆。登陆后然后查询得到最新的帖子URL列表。。
然后逐一的回复。。
在最后一步 回复的时候 总是不成功。。。
请问下 大伙 要怎么实现啊
副上我自己的代码 也是参考网上的代码的
m_HtmlDoc=(IHTMLDocument2 *)m_Web.get_Document();
EnumForm(m_HtmlDoc);
void CMyDlg::EnumFrame( IHTMLDocument2 * pIHTMLDocument2 )
{
IHTMLFramesCollection2 *FramesCollection2;
HRESULT hr=pIHTMLDocument2->get_frames(&FramesCollection2);
if ( FAILED ( hr ) ) MessageBox("获取框架集合错误");
long Length;
hr=FramesCollection2->get_length(&Length);
if ( FAILED ( hr )||Length==0) return;
for(long i=0;i<>
{
CComVariant vDispWin2;
FramesCollection2->item(&CComVariant(i), &vDispWin2);
if ( FAILED ( hr ) ) continue;
IHTMLWindow2 *spWin2;// = (IHTMLWindow2 *)vDispWin2.pdispVal;
vDispWin2.pdispVal->QueryInterface(IID_IHTMLFrameBase2,(void **)&spWin2);
if( !spWin2 ) continue; //取得子框架的 IHTMLWindow2 接口
IHTMLDocument2 *spDoc2;
spWin2->get_document( &spDoc2 ); //取得字框架的 IHTMLDocument2 接口
EnumForm( spDoc2 ); //递归枚举当前子框架 IHTMLDocument2 上的表单form
}
}
void CMyDlg::EnumForm( IHTMLDocument2 * pIHTMLDocument2 )
{
if( !pIHTMLDocument2 ) return;
EnumFrame( pIHTMLDocument2 ); //递归枚举当前 IHTMLDocument2 上的子框架fram
HRESULT hr;
CComBSTR bstrTitle;
pIHTMLDocument2->get_title( &bstrTitle ); //取得文档标题
/*USES_CONVERSION;
cout << _T("====================") << endl;
cout << _T("开始枚举“") << OLE2CT( bstrTitle ) << _T("”的表单") << endl;
cout << _T("====================") << endl;*/
IHTMLElementCollection *spElementCollection;
hr = pIHTMLDocument2->get_forms( &spElementCollection ); //取得表单集合
if ( FAILED( hr ) )
{
MessageBox("获取表单的集合 IHTMLElementCollection 错误");
return;
}
long nFormCount=0; //取得表单数目
hr = spElementCollection->get_length( &nFormCount );
if ( FAILED( hr ) )
{
MessageBox("获取表单数目错误");
return;
}
for(long i=0; i<>
{
IDispatch *pDisp = NULL; //取得第 i 项表单
hr = spElementCollection->item( CComVariant( i ), CComVariant(), &pDisp );
if ( FAILED( hr ) ) continue;
IHTMLFormElement *spFormElement;
//void *p;
pDisp->QueryInterface(IID_IHTMLFormElement,(void **)&spFormElement);
//spFormElement=(IHTMLFormElement *)p;
pDisp->Release();
long nElemCount=0; //取得表单中 域 的数目
hr = spFormElement->get_length( &nElemCount );
if ( FAILED( hr ) ) continue;
for(long j=0; j<>
{
CComDispatchDriver spInputElement; //取得第 j 项表单域
hr = spFormElement->item( CComVariant( j ), CComVariant(), &spInputElement );
if ( FAILED( hr ) ) continue;
CComVariant vName,vVal,vType; //取得表单域的 名,值,类型
hr = spInputElement.GetPropertyByName( L"name", &vName );
if( FAILED( hr ) ) continue;
hr = spInputElement.GetPropertyByName( L"value", &vVal );
if( FAILED( hr ) ) continue;
hr = spInputElement.GetPropertyByName( L"type", &vType );
if( FAILED( hr ) ) continue;
CString strCString="baidu";
vVal.bstrVal=strCString.AllocSysString();
spInputElement.PutPropertyByName(L"value",&vVal);
}
//想提交这个表单吗?删除下面语句的注释吧
hr=spFormElement->submit();
}
}
解决方案1: 做过类似的,不过那论坛除了15秒恶意罐水别的没做啥特别处理,建议抓包用webbrower post数据
解决方案2:解决方案3: hr = spElementCollection->item( CComVariant( i ), CComVariant(), &pDisp );
我以前做这种软件的时候,发现一个网站在同一页面内定义多个资源,ITEM必须标识出是第几个,否则默认是0,这个在MSDN上有详细说明,不知道是不是跟你的问题一样
解决方案4: 顶一个
解决方案5: 不好意思,由于从事行业不同,蔽人对此不是很懂:(。只是把当年遇到的一些情况告知一下。
如果是一个什么值造成的结果,那建议你抓包来对比分析一下,或者跟踪调试一下,看看提交的时候网页都干了什么?
解决方案6: 报什么错?DOM对象是否找对了?
以前做个类似功能,但发现有些网站是有两套脚本的。真正执行的并不是我们通过IHTML***找到的,而是另外一个。
以上介绍了“ 模拟论坛发贴!!有个问题严重困饶我。。高人来啊”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/3113706.html