Jump to content
Sign in to follow this  
cmux

Ampersand: '&' breaking the url stored as a variable

Recommended Posts

cmux

Hi All,

Firstly, apologies if this has been covered somewhere on this forum. I have searched high and low both here, other forums and googled the hell out of it.

I have a script that among other things, pulls a text file containing a list of URLs into an array and then opens each one in a new tab in Internet Explorer.

The problem is that some of my URLs contain an ampersand '&' and so when the script reads the variable that contains such a URL, it stops where the '&' is and so the web page is not displaye/rendered correctly.

Here is the code in question:

Func _OpenURLs()
If Not _FileReadToArray("c:\Capture\retailURLs.txt",$aRecords) Then
MsgBox(4096,"Error", " Error reading log to Array error:" & @error)
Exit
EndIf
For $x = 1 to $aRecords[0]
;Msgbox(0,'Record:' & $x, $aRecords[$x])
;$command = 'START "" '
$url = $aRecords[$x]
_RunDos("START " & $url)
Sleep(1000)
; Set Internet to full screen mode
Send("{F11}")
Next
EndFunc

The "retailURLs.txt" contain 40+ URLs, all on their own line. An example resembles something like this:

http://servername/ReportServer?%2fReportName%2fReport+Screen+Reports%2fRPT_ProductsMissingDistributionByStateByCategory&rs:Command=Render&rc:Toolbar=false&rs:ClearSession=true

I have tried substituting the "&' with "%26" and also trying to add '"' before an after the variable, which usually works in situations like this. I think it has got something to do with the fact that I am using the DOS command "START" to call the URLs into Internet Explorer.

Any thoughts and comments will be appreciated.

Cheers

Share this post


Link to post
Share on other sites
Aipion

See if this works for you.

Func _OpenURLs()
Local $aRecords
If Not _FileReadToArray("c:CaptureretailURLs.txt",$aRecords) Then
MsgBox(4096,"Error", " Error reading log to Array error:" & @error)
Exit
EndIf
For $x = 1 to $aRecords[0]
;Msgbox(0,'Record:' & $x, $aRecords[$x])
;$command = 'START "" '
$url = $aRecords[$x]
If IsDeclared("oIEx") Then
_IENavigate($oIEx, $url)
Else
Local $oIEx = _IECreate($url)
; Set Internet to full screen mode
Send("{F11}")
EndIf
Next
EndFunc

Share this post


Link to post
Share on other sites
wakillon

Try like this :oops:

#Include <File.au3>
#include <IE.au3>


Global Const $navOpenInNewTab = 0x0800
Global $aRecords, $oIE

_OpenURLs()


Func _OpenURLs()
    If Not _FileReadToArray('c:CaptureretailURLs.txt',$aRecords) Then
       MsgBox(4096,'Error', ' Error reading log to Array error:' & @error)
       Exit
    EndIf
    _IEErrorNotify ( False )
    For $x = 1 to $aRecords[0]
       ConsoleWrite ( '$aRecords[' & $x & '] : ' & $aRecords[$x] & @Crlf )
       If $aRecords[$x] Then
            If Not IsObj ( $oIE ) Then
                $oIE = _IECreate ( $aRecords[$x] )
            Else
                  __IENavigate ( $oIE, $aRecords[$x], 1, $navOpenInNewTab )
            EndIf
        EndIf
     Next
     WinMove ( _IEPropertyGet ( $oIE, 'hwnd' ), '', 0, 0, @DesktopWidth, @DesktopHeight ) ; WinSetState ( _IEPropertyGet ( $oIE, 'hwnd' ), '', @SW_MAXIMIZE )
     _IEErrorNotify ( True )
EndFunc

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites
cmux

Thanks both of you for your responses!

@wakillon Ive been playing with your script and have been reading the help topics on _IECreate and _IENavigate (__IENavigate is unsupported... Didn't even know it existed!) The first goal has been achieved, that the full URL including the ampersand ('&') is opened in Internet Explorer, however the _IECreate does not recognise that my page has loaded completley or something. For example, if I use www.google.com or www.autoitscript.com, even http://www.google.com.au/?=&#hl=en&gs_nf=1&cp=2&gs_id=7&xhr=t&q=%26%26&pf=p&output=search&sclient=psy-ab&pbx=1&oq=%26%26&aq=0&aqi=g4&aql=&gs_sm=&gs_upl=&bav=on.2,or.r_gc.r_pw.r_qf.,cf.osb&fp=3a9fd4bda99ebf6b&biw=1600&bih=1199 , the script moves onto the next URL.

How do I get create/navigate to open in a new tab and move to the next URL regardless of whether it thinks the page is loaded or not?

Share this post


Link to post
Share on other sites
cmux

Global Const $navOpenInNewTab = 0x0800
Global Const $navOpenInBackgroundTab = 0x1000
Global $aRecords, $oIE
; Init
HotKeySet("{F12}", "EndScript") ; if F12 key is pressed, run the code function "EndScript"
_OpenURLs()
_Main()
Func _OpenURLs()
    If Not _FileReadToArray('c:CaptureretailURLs.txt',$aRecords) Then
       MsgBox(4096,'Error', ' Error reading Retail Screen URLs into Array error:' & @error)
       Exit
    EndIf
    _IEErrorNotify ( False )
    For $x = 1 to $aRecords[0]
       ConsoleWrite ( '$aRecords[' & $x & '] : ' & $aRecords[$x] & @Crlf )
       If $aRecords[$x] Then
            If Not IsObj ( $oIE ) Then
    ; $oIE = _IECreate ( $aRecords[$x] )
    $oIE = _IECreate ( "about:blank" )
            Else
                  __IENavigate ( $oIE, $aRecords[$x], 1, $navOpenInNewTab)
            EndIf
        EndIf
     Next
     WinMove ( _IEPropertyGet ( $oIE, 'hwnd' ), '', 0, 0, @DesktopWidth, @DesktopHeight ) ; WinSetState ( _IEPropertyGet ( $oIE, 'hwnd' ), '', @SW_MAXIMIZE )
     _IEErrorNotify ( True )
$oIE = _IEAttach ( "Blank Page" )
; MsgBox(0, "The URL", _IEPropertyGet ($oIE, "locationurl"))
Send("^{TAB}")
Send("^{w}")
Send("{F11}")
EndFunc
Exit

Ok! I have got a work around. I use the background tab method and also call the first page as "about:blank" and then close that tab once all the tabs are opened. Now all I need to do is to work out how to get rid of that pesky right hand side scroll bar!

Share this post


Link to post
Share on other sites
wakillon

Ok! I have got a work around. I use the background tab method and also call the first page as "about:blank" and then close that tab once all the tabs are opened. Now all I need to do is to work out how to get rid of that pesky right hand side scroll bar!

Try to add $oIE.document.body.scroll = "no"


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites
cmux

Try to add $oIE.document.body.scroll = "no"

Thanks, I actually did try that however it did not work for me. Can you suggest where it should go? Does it work for you?

Share this post


Link to post
Share on other sites
wakillon

Thanks, I actually did try that however it did not work for me. Can you suggest where it should go? Does it work for you?

I'm on IE7 and it doesn't work, may be you too?


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites
cmux

I tried it on 7 and then upgraded it to 8. The box is a virtual XP SP3 machine running on VMware (ESX).

Oh well, looks like I may need to rewrite this part of the script (again!), as this is to be used for digital signage. The same page opens in Mozilla without the scrollbar however there are not the same functions built in to autoIt.

Share this post


Link to post
Share on other sites
cmux

Just found this page. Looks like there are some UDFs for firefox that could be of use.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×