URL changer

Discussions and Tech Support related to website data extraction, screen scraping and data mining using iMacros.
Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information: CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
Post Reply
Posts: 2
Joined: Mon Aug 23, 2010 11:49 pm

URL changer

Post by Flipperbw » Tue Aug 24, 2010 12:36 am

Hi all, not much experience with iMacros, and getting a bit confused with the syntax. Maybe someone can help:

I want to:

Set a bookmarklet that will allow me to change part of the URL with a predetermined string. For example, if the url were
http://www.iopus.com/thing/other/etc , I would want to change the etc to say, flipperbw, for a final url of

But I'd want to be able to edit that last directory regardless of what precedes it. so given x.com/y/z, I should always be able to click the bookmarklet, and it will replace z with some string I specify earlier.

I tried the URL extraction. But I have no idea what to do with it now. :oops:
Tom, Tech Support
Posts: 3527
Joined: Mon May 31, 2010 4:59 pm

Re: URL changer

Post by Tom, Tech Support » Wed Aug 25, 2010 4:08 pm

Hello Flipperbw,

You need to use scripting to accomplish this type of string manipulation. Here's one example using vbscript.


Code: Select all

Dim im, ret, macro, url

Set im = CreateObject("iMacros")

macro = "CODE:URL GOTO=http://www.iopus.com/imacros/compare/all" & vbNewLine
macro = macro & "SET !EXTRACT {{!URLCURRENT}}" & vbNewLine
macro = macro & "PROMPT Enter<SP>string<SP>to<SP>replace<SP>the<SP>end<SP>of<SP>the<SP>current<SP>URL: !VAR1" & vbNewLine
macro = macro & "ADD !EXTRACT {{!VAR1}}" & vbNewLine


url = im.iimGetLastExtract(1)
newEnd = im.iimGetLastExtract(2)

Dim newURL, pos

pos = -1

If Right(url, 1) = "/" Then
	pos = Len(url) - 1
End If

newURL = Left(url, InStrRev(url, "/", pos)) & newEnd

MsgBox "New URL is: " & newURL & vbNewLine & vbNewLine & "Press OK to navigate to this URL", , "URL Changer"

Assert(im.iimPlay("CODE:URL GOTO=" & newURL))

Sub Assert(retCode)

	If retCode < 0 Then
		MsgBox im.iimGetLastError(), vbCritical, "Macro Error: " & retCode
	End If
End Sub

Tom, iMacros Support
Posts: 2
Joined: Mon Aug 23, 2010 11:49 pm

Re: URL changer

Post by Flipperbw » Thu Aug 26, 2010 12:23 am

Thanks Tom. Would definitely not have figured that out!
Post Reply