Sign in to follow this  
Followers 0
Gstadig

Quick Fix for a Noob - Save File w/ Random Name

3 posts in this topic

I need to login to a website that displays XML statistics that is secured via Windows Type Security pop-up, and download / save the page as MyData.XML.

I solved the login delema via AutoIt and Selenium Web Driver/ Java

I used AutoIt to wait for the login pop-up and enter the auth see code snip below:

WinWaitActive("Authentication Required")
Send("MyUsername")
Send("(TAB)")
Send("MyPassword")
Send("(ENTER)")

I then compiled this to .exe and then called the EXE in Java, so I can get through the auth of the page. This works great

31a0450b-a3b5-4a92-90e1-cc347619dcce

 

I am looking for help in extending this simple script setup now, the most basic option is #1 below, I have a tool that will parse the collected files to give the trends, but if I could do the whole thing as in #2 that would be fantastic. 

1. - Download the webpage to a File in a Dir and increment the name Myfile1, Myfile2, Myfile3 etc since I am planning on collecting the data several times an hour. This way I can collect the page data and parse after the fact for historical data and have a history albeit many small files.

2. - Ideally I would like to parse the the web xml for a value in the page and return only the needed value, in my case this is the field <listeners> which has a number that is 1-10 digits immediately following it ie.. <listeners>1010  ie.  <listeners>99  ie. <listeners>5        - and save just the value to a CSV file or Log appending the entry to the file with the current date and time collected of the session and the value returned. Ie. make an entry into a log like   20161112, 12:00, 105     My goal is to capture the value to have a historical trend of listeners over time.

My initial thought to achieve this was to use a java routine, then i thought I maybe best to just add on to my AutoIt code since I am beyond the auth i can just grab the file and save since it would be simpler.

If anyone could provide some suggestions and snippets to solve item 1 and or 2 it would be appreciated. 

If I could do the whole process in AutoIt with an exe that would be much simpler, I just couldn't figure out or locate anything to get me there.

I am very new to to coding and know this is probably a very simple method, but I just haven't figured out the added pieces.

Thanks up front for any help you provide

 

 

 

 

 

 

Share this post


Link to post
Share on other sites



Example of the partial XML

For option #2

The value following the Listeners Field is the one I want to capture in this case the value is 4        <listeners>4  

 

<?xml version="1.0"?>
<icestats><admin>icemaster@localhost</admin><client_connections>510629</client_connections><clients>5</clients><connections>522467</connections><file_connections>42372</file_connections><host>icecast</host><listener_connections>54388</listener_connections><listeners>4</listeners><location>Earth</location><server_id>Icecast 2.3.3</server_id><server_start>Sun, 16 Aug 2015 16:57:08 -0400</server_start><source_client_connections>75</source_client_connections><source_relay_connections>0</source_relay_connections><source_total_connections>75</source_total_connections><sources>1</sources><stats>0</stats><stats_connections>0</stats_connections><source mount="/wnub.mp3"><audio_info>bitrate=128;channels=2;samplerate=44100;quality=1%2e5</audio_info><channels>2</channels><genre>College Radio</genre><listener_peak>15</listener_peak><listeners>4</listeners><listenurl>http://icecast:8000/wnub.mp3</listenurl><max_listeners>unlimited</max_listeners><public>0</public><quality>1.5</quality><samplerate>44100</samplerate><server_description>WNUB Radio 88.3FM out of Norwich University in Northfield, VT</server_description><server_name>WNUB</server_name><server_type>audio/mpeg</server_type

Share this post


Link to post
Share on other sites

To get the XML from the web and save it with auto increasing file name you can do this:

#include <Inet.au3>

$sUrl = ""
If $sUrl = "" Then
    MsgBox(0, "Error", "You have to specify an URL to test this script")
    Exit
EndIf

$XML = _INetGetSource($sURL)
$FileName = "MyFile " & StringReplace(StringReplace(_NowCalc(), "/", ""), ":", "") & ".xml"
FileWrite($FileName, $XML)

To get all <listeners> keys from the XML and save it to a CSV you can do this:

#include <Array.au3>
#include <Date.au3>

$XML = ClipGet()
While Not StringInStr($XML, '<?xml version="1.0"?>')
    If MsgBox(5, "For Testing", "Please copy the XML content into the clipboard to test this script") = 2 Then Exit
    $XML = ClipGet()
WEnd

$aListeners = StringRegExp($XML, '(?:<listeners>)(\d+)(?:</listeners>)', 3)

$sLog = ""
For $i = 0 To UBound($aListeners)-1
    $sLog &= _NowCalcDate() & "," & _NowTime() & "," & $aListeners[$i] & @CRLF
Next

If $sLog <> "" Then FileWrite("LogFile.csv", $sLog)

I don't understand this "ie" part and your XML example does not contain it either:

Quote

the field <listeners> which has a number that is 1-10 digits immediately following it ie

 

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  
Followers 0