|
|
|
date: Wed, 15 Feb 2006 04:28:29 -0800,
group: microsoft.public.inetsdk.programming.html_objmodel
back
Re: IHTMLDocument2->Write
Hi Igor,
How do I get URL's from HTML?
Can you suggest me?
When user click on anywhere of the Outlook mail, immediately it opens
webpage like ebay.com, benq.com... etc.
Now I have html body of that particular mail. Now I want to get that
particulat target link. How can I do?
Thanks in advance.
Rough code:
//pSA is html data from mail.
IHTMLDocument2* pDoc = NULL;
hr = CoCreateInstance(CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER,
IID_IHTMLDocument2, (void**)&pDoc);
hr = pDoc->write(pSA);
hr = pDoc->close();
IHTMLElementCollection* pECollection = NULL;
hr = pDoc->get_links(&pECollection);
LONG len;
hr = pECollection->get_length(&len);
for (LONG lIndex = 0; lIndex < len; lIndex ++)
{
BSTR bstrURL;
IHTMLElement* pHTMLElement = NULL;
pDisp->QueryInterface(IID_IHTMLElement,(void**)&pHTMLElement);
pHTMLElement->get_innerText(&bstrURL);
//HOW DO I GET LINKS from element?
}
Thanks in advance.
Regards,
Siri.
"Igor Tandetnik" wrote:
> "Siri" wrote in message
> news:1F1F5BDC-5D42-4B14-B4F8-21D510C3B1C2@microsoft.com
> > I have HTML data in pHTML variable and it is char*.
> >
> > How do I get IHTMLDocument2 pointer for pHTML data?
>
> See WalkAll sample for an example of using MSHTML component as HTML
> parser.
> --
> With best wishes,
> Igor Tandetnik
>
> With sufficient thrust, pigs fly just fine. However, this is not
> necessarily a good idea. It is hard to be sure where they are going to
> land, and it could be dangerous sitting under them as they fly
> overhead. -- RFC 1925
>
>
>
date: Thu, 16 Feb 2006 03:35:07 -0800
author: Siri
Re: IHTMLDocument2->Write
"Siri" wrote in message
news:C85FC770-2D99-4355-AB58-F740C7D80974@microsoft.com
> How do I get URL's from HTML?
>
> Rough code:
>
> //pSA is html data from mail.
>
> IHTMLDocument2* pDoc = NULL;
> hr = CoCreateInstance(CLSID_HTMLDocument, NULL,
> CLSCTX_INPROC_SERVER, IID_IHTMLDocument2, (void**)&pDoc);
> hr = pDoc->write(pSA);
> hr = pDoc->close();
> IHTMLElementCollection* pECollection = NULL;
> hr = pDoc->get_links(&pECollection);
> LONG len;
> hr = pECollection->get_length(&len);
> for (LONG lIndex = 0; lIndex < len; lIndex ++)
> {
VARIANT vIndex;
V_VT(&vIndex) = VT_I4;
V_I4(&vIndex) = lIndex;
VARIANT vEmpty;
VariantInit(&vEmpty);
IDispatch* pLink = 0;
pECollection->item(vIndex, vEmpty, &pLink);
BSTR bstrURL = 0;
IHTMLAnchorElement* pAnchor = 0;
IHTMLAreaElement* pArea = 0;
if (SUCCEEDED(pLink->QueryInterface(IID_IHTMLAnchorElement,
(void**)&pAnchor))) {
pAnchor->get_href(&url);
pAnchor->Release();
} else if (SUCCEEDED(pLink->QueryInterface(IID_IHTMLAreaElement,
(void**)&pArea))) {
pArea->get_href(&url);
pArea->Release();
}
pLink->Release();
if (bstrURL) {
// Do something with the URL
SysFreeString(bstrURL);
}
> }
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
date: Thu, 16 Feb 2006 08:52:37 -0500
author: Igor Tandetnik
Re: IHTMLDocument2->Write
Excellent.
It works fine.
1.)
Can I get charset value of HTML doc. like big5 or gb2312..etc?
BSTR htmlcharset;
I tried with pDoc->get_charset(&htmlcharset);
But, it is giving UNICODE always.
2.)
Can I get IP Address from the url?
Thanks in advance.
Regards,
Siri.
"Igor Tandetnik" wrote:
> "Siri" wrote in message
> news:C85FC770-2D99-4355-AB58-F740C7D80974@microsoft.com
> > How do I get URL's from HTML?
> >
> > Rough code:
> >
> > //pSA is html data from mail.
> >
> > IHTMLDocument2* pDoc = NULL;
> > hr = CoCreateInstance(CLSID_HTMLDocument, NULL,
> > CLSCTX_INPROC_SERVER, IID_IHTMLDocument2, (void**)&pDoc);
> > hr = pDoc->write(pSA);
> > hr = pDoc->close();
> > IHTMLElementCollection* pECollection = NULL;
> > hr = pDoc->get_links(&pECollection);
> > LONG len;
> > hr = pECollection->get_length(&len);
> > for (LONG lIndex = 0; lIndex < len; lIndex ++)
> > {
>
> VARIANT vIndex;
> V_VT(&vIndex) = VT_I4;
> V_I4(&vIndex) = lIndex;
> VARIANT vEmpty;
> VariantInit(&vEmpty);
> IDispatch* pLink = 0;
> pECollection->item(vIndex, vEmpty, &pLink);
>
> BSTR bstrURL = 0;
> IHTMLAnchorElement* pAnchor = 0;
> IHTMLAreaElement* pArea = 0;
> if (SUCCEEDED(pLink->QueryInterface(IID_IHTMLAnchorElement,
> (void**)&pAnchor))) {
> pAnchor->get_href(&url);
> pAnchor->Release();
> } else if (SUCCEEDED(pLink->QueryInterface(IID_IHTMLAreaElement,
> (void**)&pArea))) {
> pArea->get_href(&url);
> pArea->Release();
> }
> pLink->Release();
>
> if (bstrURL) {
> // Do something with the URL
> SysFreeString(bstrURL);
> }
>
> > }
>
> --
> With best wishes,
> Igor Tandetnik
>
> With sufficient thrust, pigs fly just fine. However, this is not
> necessarily a good idea. It is hard to be sure where they are going to
> land, and it could be dangerous sitting under them as they fly
> overhead. -- RFC 1925
>
>
>
date: Thu, 16 Feb 2006 06:55:29 -0800
author: Siri
Re: IHTMLDocument2->Write
Hi Igor,
Thank you for your cooperation.
IHTMLDocument2->write(); statement handles are increasing in task manager.
It is eating handles. How can I release handles?
obj.HrGetHTMLBody(lpMessage,&pszHTMLBody);//It returns HTML body in ascii
WCHAR* pbstrHTMLBody;
HrStrAToStrW(pHTMLBody,&pbstrHTMLBody);
SAFEARRAY *pSA;
SAFEARRAYBOUND aDim[1];
aDim[0].lLbound= 0;
aDim[0].cElements= 2;
pSA= SafeArrayCreate(VT_VARIANT,1,aDim);
VARIANT vOut;
VariantInit(&vOut);
vOut.vt= VT_BSTR;
vOut.bstrVal= SysAllocString(pbstrHTMLBody);
SafeArrayPutElement(pSA, &aLong, &vOut);
IHTMLDocument2* pDoc = NULL;
CoCreateInstance(CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER,
IID_IHTMLDocument2, (void**)&pDoc);
hr= pDoc->write(pSA);
if (pDoc != NULL){
pDoc->clear();
pDoc->Release();
}
VariantClear(&vOut);
SafeArrayDestroy(pSA);
MAPIFreeBuffer (pbstrHTMLBody);
Thanks in advance.
Regards,
Siri.
"Igor Tandetnik" wrote:
> Siri wrote:
> > 1.)
> > Can I get charset value of HTML doc. like big5 or gb2312..etc?
> >
> > BSTR htmlcharset;
> > I tried with pDoc->get_charset(&htmlcharset);
> >
> > But, it is giving UNICODE always.
>
> Not in my experience. I've just tried it on www.baidu.com and got back
> gb2312
>
> > 2.)
> > Can I get IP Address from the url?
>
> Extract the server name from the URL, then use gethostbyname
> --
> With best wishes,
> Igor Tandetnik
>
> With sufficient thrust, pigs fly just fine. However, this is not
> necessarily a good idea. It is hard to be sure where they are going to
> land, and it could be dangerous sitting under them as they fly
> overhead. -- RFC 1925
>
>
>
date: Mon, 20 Feb 2006 05:17:28 -0800
author: Siri
|
|