如何提取HTML代码里的Src连接..比如Img和BgSound的SRC...

GuoJunWei 2006-03-16 02:09:35
如何提取HTML代码里的Src连接..比如Img和BgSound的SRC...希望各位高手指点一下.小弟先谢谢了.
另外谁有邮件那方面的代码..给一份....
...全文
174 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
ccrun.com 2006-03-18
  • 打赏
  • 举报
回复
//---------------------------------------------------------------------------
#include <mshtml.h>
#include <comobj.hpp>

//---------------------------------------------------------------------------
// 获取指定页面的所有图片链接,保存到pList中
int CrnGetHtmlImageList(IHTMLDocument2 *spDoc, TStrings *pList)
{
pList->Clear();

IHTMLElementCollection *pEleColl;
IHTMLAnchorElement *pAnchorElement;
IHTMLImgElement *pImgElement;
IHTMLEmbedElement *pEmbedElement;
IHTMLScriptElement *pScriptElement;
IHTMLFormElement *pFormElement;

IDispatch *pDisp = NULL;
long lItemLen;
int nLen(0);
LPWSTR lpwAnchorHref, lpwSrc, lpwText, lpwFormAction;
spDoc->get_images(&pEleColl);
VARIANT vTemp, vIndex;
// 63 63 72 75 6E 2E 63 6F 6D
pEleColl->get_length(&lItemLen);
for(long i=0; i<lItemLen; i++)
{
vIndex.vt = VT_I2;
vIndex.lVal = i;
pEleColl->item(vIndex, vTemp, &pDisp);
if(pDisp == NULL)
continue;
if(SUCCEEDED(pDisp->QueryInterface(
IID_IHTMLImgElement, (void **)&pImgElement)))
{
pImgElement->get_src(&lpwSrc);
pList->Add(lpwSrc);
nLen++;
pImgElement->Release();
}
}
return nLen;
}
//---------------------------------------------------------------------------
// 从CppWebBrowser窗口获取 IHTMLDocument2接口
IHTMLDocument2 *__fastcall CrnGetDocInterfaceFromCwb(TCppWebBrowser *cwb)
{
IHTMLDocument2 *spDoc = NULL;
if(!cwb->Busy && cwb->Document != NULL)
cwb->Document->QueryInterface(
::IID_IHTMLDocument2, reinterpret_cast<void**>(&spDoc));
return spDoc;
}
//---------------------------------------------------------------------------
// 测试代码
void __fastcall TForm1::Button1Click(TObject *Sender)
{
CppWebBrowser1->Navigate(WideString("www.ccrun.com"));
while(CppWebBrowser1->Busy)
Application->ProcessMessages();
CrnGetHtmlImageList(CrnGetDocInterfaceFromCwb(CppWebBrowser1), Memo1->Lines);
}
//---------------------------------------------------------------------------
结果类似于:
http://www.ccrun.com/!image/logo.gif
http://www.ccrun.com/!image/banner.gif
http://www.ccrun.com/!image/014.gif
http://www.ccrun.com/!image/bg1.gif
http://www.ccrun.com/!image/user.gif
http://www.ccrun.com/forum/forum_images/log_off_icon.gif
http://www.ccrun.com/!image/forumnewtopic.gif
...

1,317

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder 网络及通讯开发
社区管理员
  • 网络及通讯开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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