Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Grab Current URL From Firefox


  • Please log in to reply
17 replies to this topic
godsstigma
  • Members
  • 222 posts
  • Last active: May 13 2011 03:09 AM
  • Joined: 04 Nov 2008
I am working on an auto-stumble script for a couple people and have an issue with grabbing the current URL address in Firefox.

Right now I am just sending F6 to highlight the address bar and collect that text, but this is very inefficient and can produce issues if the caret is already in the address or search bar.
Firefox does not display any kind of control text I can grab either.

I need these URLs to put into a database of recent stumbles and Stumble Upon doesn't offer an API of any sort, so I am a bit lost.

Does anyone have any ideas?

Lexikos-nli
  • Guests
  • Last active:
  • Joined: --
You could try the MozRepl extension. See Remotely control Firefox, or more specifically my example.

jethrow
  • Moderators
  • 2854 posts
  • Last active: May 17 2017 01:57 AM
  • Joined: 24 May 2009
Based on this thread.

This seems to work for me. I'm using a portable copy of firefox - not sure if that will make a difference or not:
SessionStorePath := "" ; enter sessionstore.js FileName

WinGetTitle, WinTitle, ahk_class MozillaUIWindowClass
StringReplace, WinTitle, WinTitle, % " - Mozilla Firefox"
needle = "url":"([^"]*?)","title":"%WinTitle%

FileRead, data, %SessionStorePath%
RegExMatch(data,needle,match)
MsgBox, %match1%
The path to the sessionstore.js file should be something like: %A_AppData%\Mozilla\Firefox\Profile\your profile name\sessionstore.js

SoLong&Thx4AllTheFish
  • Members
  • 4999 posts
  • Last active:
  • Joined: 27 May 2007
I've been using Seans' method for a long time:
Retrieve AddressBar of Firefox through DDE Message
<!-- m -->http://www.autohotke...ic19169-15.html<!-- m -->

Believer
  • Members
  • 41 posts
  • Last active: Jan 27 2011 11:55 AM
  • Joined: 13 Jun 2008
I wrote something similar a while ago, and used ctrl+l (control plus L) to highlight the address bar URL, seemed to be very effective and stable ... and simple.

Hasso
  • Members
  • 328 posts
  • Last active: Jul 01 2017 12:42 PM
  • Joined: 23 Mar 2005

I wrote something similar a while ago, and used ctrl+l (control plus L) to highlight the address bar URL, seemed to be very effective and stable ... and simple.

F6 and Alt+s work as well...
Hasso

Programmers don't die, they GOSUB without RETURN

godsstigma
  • Members
  • 222 posts
  • Last active: May 13 2011 03:09 AM
  • Joined: 04 Nov 2008
Thanks guys!!

Based on this thread.

This seems to work for me. I'm using a portable copy of firefox - not sure if that will make a difference or not:

SessionStorePath := "" ; enter sessionstore.js FileName

WinGetTitle, WinTitle, ahk_class MozillaUIWindowClass
StringReplace, WinTitle, WinTitle, % " - Mozilla Firefox"
needle = "url":"([^"]*?)","title":"%WinTitle%

FileRead, data, %SessionStorePath%
RegExMatch(data,needle,match)
MsgBox, %match1%
The path to the sessionstore.js file should be something like: %A_AppData%\Mozilla\Firefox\Profile\your profile name\sessionstore.js


Jethrow - This is very very cool. I had no idea that Firefox kept this data.
The only problem with reading the sessionrestore.js file is that Firefox waits about 1 second AFTER the page is fully loaded to write to this file, which is not a huge problem.

Lexikos - I haven't had time to check this out yet, it will take me a minute to wrap my head around what you are doing. but it seems like some very cool stuff as well as hugov's suggestion of using DDE.

Thanks everyone for their valued and highly appreciated help.
This is why i keep coming back to AHK.

chris966
  • Guests
  • Last active:
  • Joined: --

I've been using Seans' method for a long time:
Retrieve AddressBar of Firefox through DDE Message
http://www.autohotke...ic19169-15.html

thats interesting - how exactly do you use it though? doesn't really make sense to me

SoLong&Thx4AllTheFish
  • Members
  • 4999 posts
  • Last active:
  • Joined: 27 May 2007
Download <!-- m -->https://ahknet.autoh...Scripts/DDE.zip<!-- m -->
and simply run DDEMessage.ahk

You could create a function for, make a label and #include it in your script it or simply run the Script
run DDEMessage.ahk
and it will place title & url on the clipboard for further processing, by adopting the script you can have the title or url only. Works with FF, IE and Opera as far as I know.

Gauss
  • Members
  • 203 posts
  • Last active: Jan 27 2012 12:49 PM
  • Joined: 10 Sep 2009

Download <!-- m -->https://ahknet.autoh...Scripts/DDE.zip<!-- m -->
and simply run DDEMessage.ahk

You could create a function for, make a label and #include it in your script it or simply run the Script

run DDEMessage.ahk
and it will place title & url on the clipboard for further processing, by adopting the script you can have the title or url only. Works with FF, IE and Opera as far as I know.


How can I get the URL only? no "s and no title

SoLong&Thx4AllTheFish
  • Members
  • 4999 posts
  • Last active:
  • Joined: 27 May 2007

How can I get the URL only? no "s and no title

Don't have the files at hand but look at the sData or sInfo or clipboard variable they contain the url & title. You can simply stringtrim, substr or stringsplit? etc to get either the url or the title

Gauss
  • Members
  • 203 posts
  • Last active: Jan 27 2012 12:49 PM
  • Joined: 10 Sep 2009

How can I get the URL only? no "s and no title

Don't have the files at hand but look at the sData or sInfo or clipboard variable they contain the url & title. You can simply stringtrim, substr or stringsplit? etc to get either the url or the title


How do I get what is between the first 2 ""?
So insteend of this:
"http://www.google.com/intl/en/","Google",""
this:
<!-- m -->http://www.google.com/intl/en/<!-- m -->

Tuncay
  • Members
  • 1945 posts
  • Last active: Feb 08 2015 03:49 PM
  • Joined: 07 Nov 2006

How do I get what is between the first 2 ""?
So insteend of this:
"http://www.google.com/intl/en/","Google",""
this:
<!-- m -->http://www.google.com/intl/en/<!-- m -->

Look at this:
list = "http://www.google.com/intl/en/","Google","" 
Loop, Parse, list, CSV
    MsgBox %A_LoopField%

No signature.


Gauss
  • Members
  • 203 posts
  • Last active: Jan 27 2012 12:49 PM
  • Joined: 10 Sep 2009

Look at this:

list = "http://www.google.com/intl/en/","Google","" 
Loop, Parse, list, CSV
    MsgBox %A_LoopField%


Hmm..
Why is it so difficult :?
I just want the URL and not the title

I added yours like this:

Clipboard := % sData
list = %Clipboard%
Loop, Parse, list, CSV
MsgBox %A_LoopField%

But then I get 3 msg boxes, url, title and an empty one!

And all I want is to have the url on the clipboard

I believe there is a way to even edit DDEML.ahk itself so it returns with that only, I just don't know how

SoLong&Thx4AllTheFish
  • Members
  • 4999 posts
  • Last active:
  • Joined: 27 May 2007
Here are three methods, pretty basic stuff, read up on strings !
clipboard="http://www.google.com/intl/en/","Google","" 
;method one
url1:=substr(clipboard,instr(clipboard,Chr(34))+1,instr(clipboard,Chr(34),false,2)-2)
MsgBox % Url1 
;method two
Loop, parse, clipboard, csv
	{
	 url2:=A_LoopField
	 Break
	} 
MsgBox % Url2
;method three
StringSplit, url3, clipboard, `,
MsgBox % Url31 ; still need to trim "
StringTrimLeft, Url31, Url31, 1
StringTrimRight, Url31, Url31, 1
MsgBox % Url31 ; correct
You could also use RegExReplace and a number of other methods I'm sure.