blakela Posted July 1, 2008 Posted July 1, 2008 My scripting/coding skills ended with my last fortran class in 1979 but now I find myself needing to automate some tasks. So I am obviously already way over my head. I need to call a URL which returns several lines of text, finds a specific parameter and sets that to a variable. I am calling the URL with _IECreate command. The result of the call is: <?xml version="1.0" encoding="utf-8" ?> - <results> <status code="ok" /> - <common locale="en" time-zone-id="85"> <cookie>ABC21341iasdfsaf</cookie> <date>2008-07-01T03:45:30.780+00:00</date> <host>http://hostname.com</host> <local-host>abadabado</local-host> <admin-host>admin.hostname.com</admin-host> <url>/api/xml?action=common-info&domain=hostname.com</url> <version>app_700_r713</version> <account account-id="123456987" /> <user-agent>Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 1.1.4322; InfoPath.1; .NET CLR 2.0.50727; MS-RTC LM 8)</user-agent> </common> </results> I want to get the string for "cookie" and use it as a varible in my overall script. Even extracting that string and writing to a single line text file that I could read back later would be a step in the right direction. If anyone can point me to other forums or help files to read I'd be happy to but so far I cannot find anything that lets me do this.
goldenix Posted July 1, 2008 Posted July 1, 2008 thats pretty easy: Search the webpage source code for <cookie>, note that autoit forum source has <cookie> instead of <cookie>$oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("GET",'http://www.autoitscript.com/forum/index.php?showtopic=74983') $oHTTP.Send() $HTMLSource = $oHTTP.Responsetext $_Arrayline = StringSplit($HTMLSource, @LF) ; this is the Array $_Arrayline ;~ for $i = 1 to $_Arrayline[0] If StringInStr($_Arrayline[$i],'<cookie>') Then ; search source for <cookie> $Group_Key_Item = StringRegExp($_Arrayline[$i], '<(?i)cookie>(.*?)</(?i)cookie>', 2); get Item $Group_Key_Item = $Group_Key_Item[1] ConsoleWrite($Group_Key_Item & @CRLF) ;~ ExitLoop EndIf Next My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]
blakela Posted July 1, 2008 Author Posted July 1, 2008 thats pretty easy: Search the webpage source code for <cookie>, note that autoit forum source has <cookie> instead of <cookie> $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("GET",'http://www.autoitscript.com/forum/index.php?showtopic=74983') $oHTTP.Send() $HTMLSource = $oHTTP.Responsetext $_Arrayline = StringSplit($HTMLSource, @LF) ; this is the Array $_Arrayline ;~ for $i = 1 to $_Arrayline[0] If StringInStr($_Arrayline[$i],'<cookie>') Then ; search source for <cookie> $Group_Key_Item = StringRegExp($_Arrayline[$i], '<(?i)cookie>(.*?)</(?i)cookie>', 2); get Item $Group_Key_Item = $Group_Key_Item[1] ConsoleWrite($Group_Key_Item & @CRLF) ;~ ExitLoop EndIf Next Thank you. I get this error when I run the script: (12) : ==> Subscript used with non-Array variable.: $Group_Key_Item = $Group_Key_Item[1] $Group_Key_Item = $Group_Key_Item^ ERROR Any ideas?
weaponx Posted July 1, 2008 Posted July 1, 2008 #include "_XMLDomWrapper.au3" #include <Array.au3> Local $sFile = "test.xml" If FileExists($sFile) Then $ret = _XMLFileOpen($sFile) If $ret = 0 Then Exit $cookie = _GetFirstValue("//common/cookie") MsgBox(4096, "cookie", $cookie) Else MsgBox(4096, "Error", _XMLError()) EndIf ;_XMLGetValue returns an array (not sure why) this will return the first element Func _GetFirstValue($node) $ret_val = _XMLGetValue($node) If IsArray($ret_val) Then Return ($ret_val[1]) Else Return SetError(1,3,0) EndIf EndFunc
goldenix Posted July 1, 2008 Posted July 1, 2008 (edited) Thank you. I get this error when I run the script: (12) : ==> Subscript used with non-Array variable.: $Group_Key_Item = $Group_Key_Item[1] $Group_Key_Item = $Group_Key_Item^ ERROR Any ideas?Its Stringregexp, see the help file: hire is better example so you can see how we get the data: #include <Array.au3> $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("GET",'http://www.autoitscript.com/forum/index.php?showtopic=74983') $oHTTP.Send() $HTMLSource = $oHTTP.Responsetext $_Arrayline = StringSplit($HTMLSource, @LF) ; this is the Array $_Arrayline for $i = 1 to $_Arrayline[0] If StringInStr($_Arrayline[$i],'<cookie>') Then ; search source for <cookie> $array = StringRegExp($_Arrayline[$i], '<(?i)cookie>(.*?)</(?i)cookie>', 2) for $i = 0 to UBound($array) - 1 msgbox(0, "$array[" & $i & "]", $array[$i]) Next ;~ $cookie = $array[1] _ArrayDisplay($array, "blaaa") ExitLoop EndIf Next Edited July 1, 2008 by goldenix My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]
blakela Posted July 2, 2008 Author Posted July 2, 2008 Great, I was able to understand the last example and modify it for the problem at hand. However, now I find that my corporate firewall will not let me do the $oHTTP.Send() function. Is there an alternative that I can try?
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now