Abs* 12 Posted January 9, 2011 Report Share Posted January 9, 2011 hi guys so sorry about the bad title - what im doing is loading a article into a bot then searching the text for a certain word - if the word is there then it should replace with xxx xx being a anchor text - so heres the problem - on many occasions i have noticed that the word being searched for is used many times in the text and when it replaces it to a anchor text it will replace all instances of that word - which isnt what im after - what I would like is to replace upto 3 words with the anchor text and if more exist then leave them alone - I have attached a image below showing how I am currently doing it thanks wow the file is too large to attach - please view it here http://ubotstudio.com/forum/index.php?app=core&module=attach§ion=attach&attach_rel_module=post&attach_id=1851 Quote Link to post Share on other sites
Guerrilla 19 Posted January 9, 2011 Report Share Posted January 9, 2011 Haha, sounds like you are making the same bot as me! You will have to do this is javascript. I will add it to code I am making for you for other thread. Quote Link to post Share on other sites
Guerrilla 19 Posted January 9, 2011 Report Share Posted January 9, 2011 here you go. Will probably need some tidying up but worked when i tested it.replace x amount.ubot Quote Link to post Share on other sites
UBotBuddy 331 Posted January 9, 2011 Report Share Posted January 9, 2011 Interesting code Guerrilla, For me it would not replace more than one keyword. Quote Link to post Share on other sites
Guerrilla 19 Posted January 9, 2011 Report Share Posted January 9, 2011 If the word your searching for and word your replacing are the same then that will happen and it keeps replacing the first keyword. I think the regex would get a bit more complex if you are searching for and replacing same keyword as would make a loop inside the javascript to handle the replacements instead of making the loop in ubot. Quote Link to post Share on other sites
Guerrilla 19 Posted January 9, 2011 Report Share Posted January 9, 2011 Just had a little think about this and you can put a statement is so if search word and replace word are the same do a find and replace to change all instances of the keyword to a paceholder. then run it through my loops, then afterward find and replace the placeholder back to the original keyword. All should work fine then. Quote Link to post Share on other sites
Abs* 12 Posted January 10, 2011 Author Report Share Posted January 10, 2011 here you go. Will probably need some tidying up but worked when i tested it. Hi - Thank alot - For some reason when i try to download it says that the attachment was not found Maybe when the servers were unstable yesterday some attachments were lost thanks Quote Link to post Share on other sites
UBotBuddy 331 Posted January 10, 2011 Report Share Posted January 10, 2011 I typically load my document into a list and text each list item and then i build in the randomness at that point. Quote Link to post Share on other sites
Guerrilla 19 Posted January 11, 2011 Report Share Posted January 11, 2011 re-uploaded, hope this helps. This bot will only work if search keyword and anchor text are different. Hopefully though it shows you general idea so you can tidy it up for your own purposes. Gimme shout if you get stuck.replace x amount.ubot Quote Link to post Share on other sites
UBotBuddy 331 Posted January 11, 2011 Report Share Posted January 11, 2011 Sorry dude. Still did not work for me. I may try and tweak it tomm. It only does one replace. Quote Link to post Share on other sites
Guerrilla 19 Posted January 11, 2011 Report Share Posted January 11, 2011 It works, look for yourself - http://www.screencast-o-matic.com/watch/cXVXh1XSJ Not sure if you read my other posts but if you are searching for the same word as you are replacing it will only do one. This is simple to fix, just add a little extra logic. I just did this as a proof of concept. I don't know exactly the purpose the OP needs this for so didn't want to waste too much time on it. Quote Link to post Share on other sites
UBotBuddy 331 Posted January 11, 2011 Report Share Posted January 11, 2011 No problem. I just like looking at similar coding techniques. Quote Link to post Share on other sites
Abs* 12 Posted January 15, 2011 Author Report Share Posted January 15, 2011 wow - i think i will need to take out some time - have a cup of coffee while looking over the code - thanks alot Guirilla will certainly try to put it to use Quote Link to post Share on other sites
Guerrilla 19 Posted January 20, 2011 Report Share Posted January 20, 2011 No worries mate, if you get stuck just hit me up and i'll help you mod it. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.