VC中显示网页查找网页中内容访问链接,该从何开始。。。

flyboy81 2006-10-29 07:12:18
一个网页,我想把它显示在应用程序中,然后再程序中分析网页中的内容,找到指定的链接地址,再访问找到的链接地址.以前没做过这种东西,各位能不能给我一点关键字提示一下,去研究什么?我用VC,
多谢了!
...全文
314 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
wildmen 2006-11-02
  • 打赏
  • 举报
回复
hoho. 我就shut up. 顶。
蒋晟 2006-10-30
  • 打赏
  • 举报
回复
public delegate bool EnumFormInputsProc(IHTMLElement pInputElement, ref object oParam);

/// <summary>
/// Enumerates all input elements in the form by passing the IHTMLElement interface of each input element, in turn, to an application-defined callback function. EnumFormInputs continues until the last input element is enumerated or the callback function returns false.
/// </summary>
/// <remarks>The method cannot retrieve input type=image elements from a form. To access all elements contained in a form, call QueryInterface on IHTMLFormElement and request an IHTMLElement interface. Use the IHTMLElement::children property of the IHTMLElement interface to retrieve a collection of all elements in the form.</remarks>
/// <param name="form">the IHTMLFormElement interface of the form element</param>
/// <param name="enumFormInputsProc">This function is an application-defined callback function that receives input element as a result of a call to the EnumFormInputs function.</param>
/// <param name="oParam">Specifies the application-defined value given in EnumFormInputs</param>
/// <returns>true if the last input element is enumerated. otherwise false</returns>
public bool EnumFormInputs(IHTMLFormElement form, EnumFormInputsProc enumFormInputsProc, ref object oParam)
{
for (int i = 0; i < form.length; i++)
{
IHTMLElement pElement = (IHTMLElement)form.item(i, 0);
if (enumFormInputsProc(pElement, ref oParam) == false) return false;
}
return true;
}
/// <summary>
/// Enumerates all input elements in the top level document of the Webbrowser control by passing the IHTMLAnchorElement interface of each anchor element, in turn, to an application-defined callback function. EnumLinks continues until the last anchor element is enumerated or the callback function returns false.
/// </summary>
/// <param name="enumLinkProc">This function is an application-defined callback function that receives anchor element as a result of a call to the EnumLinks function.</param>
/// <param name="oParam">Specifies the application-defined value given in EnumLinks</param>
public bool EnumLinks(EnumLinkProc enumLinkProc, ref object oParam)
{
IHTMLDocument2 pDoc = (IHTMLDocument2)this.Document.DomDocument;
return EnumLinks(enumLinkProc, ref oParam, pDoc);
}

/// <summary>
/// Enumerates all input elements in the HTML document by passing the IHTMLAnchorElement interface of each anchor element, in turn, to an application-defined callback function. EnumLinks continues until the last anchor element is enumerated or the callback function returns false.
/// </summary>
/// <param name="enumLinkProc">This function is an application-defined callback function that receives anchor element as a result of a call to the EnumLinks function.</param>
/// <param name="oParam">Specifies the application-defined value given in EnumLinks</param>
/// <param name="pDoc">the IHTMLDocument2 interface of the HTML document</param>
/// <returns>true if the last input element is enumerated. otherwise false</returns>
public bool EnumLinks(EnumLinkProc enumLinkProc, ref object oParam, IHTMLDocument2 pDoc)
{
IHTMLElementCollection anchors=pDoc.links;
if(anchors!=null)
{
int i=0;
for(i=0;i<anchors.length;i++)
{
IHTMLAnchorElement iae = (IHTMLAnchorElement)anchors.item(i, 0);
if (enumLinkProc(iae, ref oParam) == false) return false;
}
}
return true;
}
public bool ScanLinkForHrefProc(IHTMLAnchorElement pAnchorElement, ref object oParam)
{
if (pAnchorElement.href.Contains(oParam.ToString()))
{
oParam = pAnchorElement;
return false;
}
return true;
}
public IHTMLAnchorElement GetLinkByHref(string Text)
{
IHTMLDocument2 pDoc = (IHTMLDocument2)this.Document.DomDocument;
return GetLinkByHref(Text, pDoc);
}
public IHTMLAnchorElement GetLinkByHref(string Text, IHTMLDocument2 pDoc)
{
object oParam=Text;
if (EnumLinks(new EnumLinkProc(ScanLinkForHrefProc)
, ref oParam,pDoc) == false)
{
return (IHTMLAnchorElement)oParam;
}
return null;
}
lion_wing 2006-10-30
  • 打赏
  • 举报
回复
学一下Webbrowser、MSHTML
Kudeet 2006-10-29
  • 打赏
  • 举报
回复
参考http://topic.csdn.net/t/20030827/13/2193169.html
Kudeet 2006-10-29
  • 打赏
  • 举报
回复
Get all Image URL
IHTMLElementCollection* p_imgColl = NULL;
if (!SUCCEEDED(hr = m_pMSHTML->get_all( &p_imgColl )))
return E_FAIL;
if(m_pParser)
{
m_pParser->Parse(p_imgColl);
p_imgColl->Release();
PostQuitMessage(0);
return S_OK;
}
// IHTMLElementCollection* p_imgColl = NULL;
// if (SUCCEEDED(hr = m_pMSHTML->get_all( &p_imgColl )))
{
long cElems=0;
// retrieve the count of elements in the collection
if (SUCCEEDED(hr = p_imgColl->get_length( &cElems )))
{
for ( int i=0; i<cElems; i++ )
{
VARIANT vIndex;
vIndex.vt = VT_UINT;
vIndex.lVal = i;
VARIANT var2 = { 0 };
LPDISPATCH pDisp;
if (SUCCEEDED(hr = p_imgColl->item( vIndex, var2, &pDisp )))
{
bool b_print_tag=true;
if(b_print_tag)
{
IHTMLImgElement* pImage = NULL;
if (SUCCEEDED(hr = pDisp->QueryInterface( IID_IHTMLImgElement, (LPVOID*)&pImage )))
{
BSTR bstr;
pImage->get_src(&bstr);
pImage->Release();
b_print_tag=false;
if (bstr)
{
SaveImg(bstr);
SysFreeString(bstr);
}
}
}
pDisp->Release();
} // item
} // for
} // get_length
p_imgColl->Release();
}

3,055

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC HTML/XML
社区管理员
  • HTML/XML社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧