Get Current URL and change it?

Support for iMacros. The iMacros software is the unique solution for automating every activity inside a web browser, for data extraction and web testing.
Forum rules
iMacros EOL - Attention!

The renewal maintenance has officially ended for Progress iMacros effective November 20, 2023 and all versions of iMacros are now considered EOL (End-of-Life). The iMacros products will no longer be supported by Progress (aside from customer license issues), and these forums will also no longer be moderated from the Progress side.

Thank you again for your business and support.

Sincerely,
The Progress Team

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
lsurow
Posts: 3
Joined: Thu Oct 16, 2008 9:50 pm

Get Current URL and change it?

Post by lsurow » Thu Oct 16, 2008 10:02 pm

Hi,

I am new to the iMacros and was wondering if anyone can help me with how to do a certain task.

I would like to get the current url, which I believe I would use SET !EXTRACTADD {{!URLCURRENT}} and then I would like to take the current url, remove the http:// and replace it with https://

For example -
current url = http://www.someurl.com

So http://www.someurl.com would become https://www.someurl.com

Thanks so much for your help

--Lisa
dharmendra2000
Posts: 214
Joined: Fri Jul 04, 2008 1:28 pm
Location: Ahmedabad
Contact:

Re: Get Current URL and change it?

Post by dharmendra2000 » Fri Oct 17, 2008 4:40 am

Hi Lisa,
It is possible using java script

You can use following code to change from http to https.....
var str="http://www.someurl.com";
newurl = str.replace(/http/,"https");

First line will store extracted url in "str" variable
Second line will replace http with https and it resulting string will be assigned to "newurl" variable which can be used for further reference.

Hope it will solve your purpose

Dharmesh Uteshiya
www.dharmesh-uteshiya.co.nr
lsurow
Posts: 3
Joined: Thu Oct 16, 2008 9:50 pm

Re: Get Current URL and change it?

Post by lsurow » Fri Oct 17, 2008 1:18 pm

Thanks so much Dharmesh! Will I be able to incorporate the !URLCURRENT into that? Basically, I want the macro to grab the current url I am on and then change it from http to https. The url will always be different which is why I was thinking I needed to use the !URLCURRENT.

thanks again for your help on this

--Lisa
User avatar
Tech Support
Posts: 4948
Joined: Tue Sep 20, 2005 7:25 pm
Contact:

Re: Get Current URL and change it?

Post by Tech Support » Fri Oct 17, 2008 7:23 pm

The complete solution is to combine your macro with dharmendra2000 code:

Macro1 extracts the URL with

Code: Select all

ADD !EXTRACT {{!URLCURREN}}
Then you can read the content of !EXTRACT from the script with oldurl=iimGetLastExtract (1), use dharmendra2000 code snippet to change http to https and then send the code to the new macro with iimSet ("url2", newurl)

Code: Select all

URL GOTO={{url2}}
lsurow
Posts: 3
Joined: Thu Oct 16, 2008 9:50 pm

Re: Get Current URL and change it?

Post by lsurow » Fri Oct 17, 2008 8:10 pm

Thanks for the help - maybe it being Friday is why I am not understanding this. how do i use javascript in the macro?

I have one .iim file called check-change-https.


My code that i have in that file is:

VERSION BUILD=6221002
TAB T=1
ADD !EXTRACT {{!URLCURRENT}}
oldurl = iimGetLastExtract (1)
newurl = str.replace(/http/,"https")
iimSet ("url2", newurl)
TAB T=2
URL GOTO={{url2}}


I am not sure why I can't get this to work and really appreciate your help on this.
User avatar
Tech Support
Posts: 4948
Joined: Tue Sep 20, 2005 7:25 pm
Contact:

Re: Get Current URL and change it?

Post by Tech Support » Fri Oct 17, 2008 9:54 pm

You need to use the Javascript or VBS script or any other language externally and then use iimPlay to start the macro.

Please see the examples at
http://wiki.imacros.net/Sample_Code (iMacros Scripting Edition)

http://wiki.imacros.net/iMacros_for_Fir ... _Interface (iMacros for Firefox)
dharmendra2000
Posts: 214
Joined: Fri Jul 04, 2008 1:28 pm
Location: Ahmedabad
Contact:

Re: Get Current URL and change it?

Post by dharmendra2000 » Mon Oct 20, 2008 5:01 am

You require 3 files to complete your task. Once all 3 files are ready, execute myscript.js file.

myscript.js

Code: Select all

iimPlay("mac1.iim")
oldurl = iimGetLastExtract (1)
newurl = oldurl.replace(/http/,"https")
iimSet ("url2", newurl)
alert(newurl);
iimPlay("mac2.iim")
mymacro1.iim

Code: Select all

VERSION BUILD=6070918 RECORDER=FX
TAB T=1
URL GOTO=http://www.google.com/
ADD !EXTRACT {{!URLCURRENT}}
mymacro2.iim

Code: Select all

VERSION BUILD=6070918 RECORDER=FX
TAB T=1
PROMPT {{url2}}
URL GOTO={{url2}}
ADD !EXTRACT {{!URLCURRENT}}
Hope this will solve your purpose

Cheers,
Dharmesh Uteshiya
http://www.dharmesh-uteshiya.co.nr
go3don
Posts: 2
Joined: Mon Mar 26, 2018 10:01 am

Re: Get Current URL and change it?

Post by go3don » Mon Mar 26, 2018 10:09 am

iMacros GOTO supports javascript so you can generate new URL like this:

Code: Select all

VERSION BUILD=1001 RECORDER=CR
URL GOTO=https://url.com/file.php?id=61460
URL GOTO=javascript:var<SP>url=new<SP>URL(window.location.href);var<SP>id=url.searchParams.get("id");window.location.href='https://url.com/post_new.php?issue_id='+id;
User avatar
thecoder2012
Posts: 446
Joined: Sat Aug 15, 2015 5:14 pm
Location: Internet
Contact:

Re: Get Current URL and change it?

Post by thecoder2012 » Wed Apr 11, 2018 6:33 pm

go3don wrote:iMacros GOTO supports javascript so you can generate new URL like this:

Code: Select all

VERSION BUILD=1001 RECORDER=CR
URL GOTO=https://url.com/file.php?id=61460
URL GOTO=javascript:var<SP>url=new<SP>URL(window.location.href);var<SP>id=url.searchParams.get("id");window.location.href='https://url.com/post_new.php?issue_id='+id;
Why with searchParams (id) ?

My example:

Code: Select all

URL GOTO=http://www.someurl.com/
ADD !EXTRACT {{!URLCURRENT}}
URL GOTO=javascript:window.location.href="{{!EXTRACT}}".replace(/^http/i,"https");
Join 9kw.eu Captcha Service now and let your iMacros continue downloads and scripts while you sleep. - Custom iMacros? Contact me! :idea:
Post Reply