Link to home
Start Free TrialLog in
Avatar of marounk
marounk

asked on

Removing a certain tag in an HTML String

Greetings,

I have a variable holding an HTML file content what I want is the following:

Remove all the <a> tags from it, what I want is to capture the link tag and remove it with its contents whatever it is an image , or a text or anything

Please help

thnx
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

HTMLString = Replace$(HTMLString,"<a>","") ?
Avatar of priya_pbk
priya_pbk

also this,
HTMLString = Replace$(HTMLString,"</a>","")

This will remove the hyperlinks from the htm page.

But as I understand from your code is you want to remove all the text within the <a> and </a> tags. If it is so, then find for <a> and </a> tags using mid or instr fns and replace that with vbnullstring(" ")

Hope this helps!

-priya



IMHO, you have two choices:
1) Second one by priya_pbk but changing the first to "<a" since there is not an "<A>" alone ;)
2) You could use HTMLDocument object.
Avatar of marounk

ASKER

where can I find example on the HTMLDocument Object ???

thnx
ASKER CERTIFIED SOLUTION
Avatar of Richie_Simonetti
Richie_Simonetti
Flag of Argentina image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Richie, I tried your example, but gives me an error at this line , ie:
lnk.disabled = True

mentions "Object doesn't support this property or method"

I have put the references and wrote down the code, it opens the IE and then shows this error.

Was curious to know how the 'lnk.disabled=true' can actually disable links in a web page!! Am I missing something here.

-priya


I did a test before post it with no problems!
Maybe a MSHTML.dll version problem?

marounk, that code didn't solve your problem?, then, why did you accept my comment as answer?
Avatar of marounk

ASKER

After adding the Refrences in VB you code did work but it is not finding any Links in any Page !!!

I did close this thread because I was desperate !

Thnx for caring
Strange, i did a test with https://www.experts-exchange.com/visualbasic/ and everything worked fine.