...

View Full Version : Delete specific data from html



elemenop
06-22-2006, 05:45 PM
I have been struggling with finding a solution for this problem for a few days, and being unfamiliar with scripting for the most part, I was hoping someone here may be able to point me in the right direction.

I setup a simple Moblog through blogger.com to record an upcoming roadtrip, and relized that my cellphone provider (Verizon) adds in some marketing blurb to evey MMS I send. This creates a mess of text and <br /> tags that I want to get rid of without having to log in and manually edit the code.

I assumed DOM scripting would be the easiest bet, to just point it to the element, check that the text string was present and if so, delete the parentnode of that text string. Unfortunetly, I can not find any information about someone dong this before, so I am stuck.

Here is the page I was testing with (http://www.platypie.com/test.htm).

Obviously, I want the script to look at the page onLoad and if it sees a text node with the specified text, to delete that node and leave only my original caption.

Thanks in advance if you can point me in a direction to look or have any ideas.

Beagle
06-22-2006, 06:19 PM
I would try always starting your messages with a special character, like _ or !

then:


var msgs = document.getElementsByTagName("P");

for (var i = msgs.length -1; i >= 0; --i)
{
if (msgs[i].className == "mobile-post")
{
if (msgs.firstChild.nodeValue.charAt(0) != "_")
msgs[i].parentNode.removeChild(msgs[i]);
}
}


You do realize though that as you add more and more to your blog that this will take more and more time, right?

elemenop
06-22-2006, 06:39 PM
Thanks for the quick reply, I will give that a shot.

I do realize that it will start to take longer and longer the more posts I add. I just want to have it there as a preliminary edit until I can get to a computer and go in and edit out the offending lines manually. That way my family can view pictures of my trip, without having to wade through post after post of verizon spam.

elemenop
06-22-2006, 08:09 PM
Hmm, Well I tried what you suggeted, but it doesn't seem to want to do anything. Maybe I am missing something.

Heres the sample page again: Test Page (http://www.platypie.com/test.htm)

Any feedback would be appreciated.

Beagle
06-22-2006, 09:30 PM
wrap the script in a function and call it onload.

Your currently running the script before the paragraphs are even there, so nothing happens.

elemenop
06-23-2006, 03:52 PM
I'm sorry, I am just not getting it. I have tried a bunch of things, and the closest I got was when I left the </script> tag off the end and none of the page displayed (boy, was I excited!).

If you could find it in your heart to look at this once more and tell me what an obvious idiot I am being, I would appreciate it.

http://www.platypie.com/test.htm

Beagle
06-23-2006, 06:19 PM
1) function remove() {

2) <body onload="remove();">

3) Scrap the bottom script block

4) If it doesn't work from there, then my code is slightly off, you should put an alert in to see what the value of charAt(0) is, try to figure out what's going on by alerting various values throughout the code to make sure your logic is working.

elemenop
06-23-2006, 07:39 PM
Beagle, thanks your brilliant!

I finally realized where the trouble was.


var msgs = document.getElementsByTagName("P");

for (var i = msgs.length -1; i >= 0; --i)
{
if (msgs[i].className == "mobile-post")
{
if (msgs[i].firstChild.nodeValue.charAt(0) != "_")
msgs[i].parentNode.removeChild(msgs[i]);
}
}

You had left that off the original sample(on purpose maybe?), and after playing with alerts for a couple minutes, it was glaringly obvious where it was going wrong. Thanks so much for your help, I learned alot!

Beagle
06-23-2006, 08:46 PM
I just double checked my original post, and you're absolutely right. I did make an error and I apologize for it. However, I'm glad that you learned a lot. It's always better that you learn something, that way you can acheive more. I hope you enjoy your trip! :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum