Assault Posted May 11, 2007 Posted May 11, 2007 Well Im trying to Get it to read the source from a site then write it to a txt, then find part of that text make it an array then send it to a tooltip.(I know my script is sending it to a msgbox) I have all of it doen except I dont know how to have it just read the part I want, <start>this is what I want</start>) #include <INet.au3> #include <file.au3> global $who global $x filewrite("a.txt",_INetGetSource('google.com')) _filereadtoarray("a.txt",$who) For $x = 1 to $who[0] Msgbox(0,'Record:' & $x, $who[$x]) Next
the_lord_mephy Posted May 11, 2007 Posted May 11, 2007 Read the whole file into a string, then $split1 = StringSplit($file, "<start>", 1) $split2 = StringSplit($split1, "</start>", 1) $split2[0] should have what you're looking for My site for HTML Help :)[quote name='Valik' date='Oct 15 2004, 12:29 PM']Maybe nobody is an "elite uber-coder" like me because thinking is a capital offense in today's online-world?[right][snapback]36427[/snapback][/right][/quote]
BrettF Posted May 11, 2007 Posted May 11, 2007 I guess try this. There probably is an eaiser way, but until someone else says..... #include <INet.au3> #include <file.au3> global $who, $x, $output filewrite("a.txt",_INetGetSource('google.com')) _filereadtoarray("a.txt",$who) For $x = 1 to $who[0] If StringInStr ($who[$x], "<start>") Then $who[$x] = StringReplace ($who[$x], "<Start>", "") $who[$x] = StringReplace ($who[$x], "</Start>", "") EndIf Next MsgBox (0, "Output " & $x, $output) UNTESTED! BTW Google has no <start> </start> tags??? Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version!
enaiman Posted May 11, 2007 Posted May 11, 2007 (edited) here is something which attempt to solve your problem; I'm sure it can be done nicer, faster, shorter ... but hey - this is how I thought it. Global $string = "", $result = "" For $x = 1 to $who[0] If StringInStr($who[$x], "<start>") Then ;if it finds <start> $to_find = StringTrimLeft ($who[$x], StringInStr($who[$x], "<start>")+6) ;cut all the left part (<start> included) If StringInStr($to_find, "</start>") Then ;if </start> if found on the same line $result = StringMid ($to_find, 1, StringInStr($to_find, "</start>")-1) ;cut the last part and $result is what you seek Else ;<start> and </start> are not on the same line (there are several lines between them) $y = $x+1 While StringInStr($who[$y], "</start>") = 0 ;read next array elements until finds </start> $y +=1 WEnd $result_last = StringMid ($who[$y], 1, StringInStr($who[$y], "</start>")-1) ;cut the right part of the last element $string &= $to_find ;start building the final result $string &= @CRLF For $z = $x+1 to $y-1 $string &= $who[$z] $string &= @CRLF Next $string &= $result_last EndIf EndIf Next MsgBox (0, "string", $string) EDIT: :"> what I've been saying about nicer, faster, shorter ? Edited May 11, 2007 by enaiman SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :)
Assault Posted May 11, 2007 Author Posted May 11, 2007 (edited) Well those would work but from the one file I want a few different things, this si what I will start with expandcollapse popup<?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="stat.xsl"?> <stats> <server> <version>0.4735.1.9</version> <owner>orangevirus</owner> <servername>|cff0000FFProject Evolution (Reb 4:20.3)|r</servername> <uptime>0 weeks 2 days 3 hours 41 mins</uptime> </server> <serverload> <network> <configsleep>200</configsleep> <loops>0</loops> <totaltime>0</totaltime> <load>0.00%</load> </network> <world> <configsleep>600</configsleep> <loops>246973</loops> <totaltime>32408270</totaltime> <load>17.40%</load> </world> </serverload> <players> <player> <name>Carnage</name> <race>2</race> <class>1</class> <level>173</level> <map>1</map> <zone>15</zone> <ping>15</ping> <plevel>0</plevel> <ip>74.103.162.35</ip> </player> </players> </stats> Now I want from this <players> <player> <name>Carnage</name> <race>2</race> <class>1</class> <level>173</level> <map>1</map> <zone>15</zone> <ping>15</ping> <plevel>0</plevel> <ip>74.103.162.35</ip> </player> </players> the name of every person on the server.(so every <name>name</name>) Im going to guess this is going to take alot, because you would have to start at <players> then get each <name> out, but I dont have any clue on how to do this. Edited May 11, 2007 by Assault
enaiman Posted May 11, 2007 Posted May 11, 2007 LOL Good luck at that.because you would have to start at <players> then get each <name> out... I'm affraid that it would be you the one to start at <players> ... SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :)
PsaltyDS Posted May 11, 2007 Posted May 11, 2007 (edited) You had the answer from the_lord_mephy back in post #2. You can read an entire multi-line file into a single string and treat it as one string for processing. Then use _StringBetween() to pull out what you want: #include <string.au3> $FilePath = "C:\Temp\Your.xml" $FileData = FileRead($FilePath, FileGetSize($FilePath)) $avPlayers = _StringBetween($FileData, "<players>", "</players>") $Names = "" If Not @error Then For $x = 0 To UBound($avPlayers) - 1 $avPlayer = _StringBetween($avPlayers[$x], "<player>", "</player>") If Not @error Then For $n = 0 To UBound($avPlayer) - 1 If StringInStr($avPlayer[$n], "<name>") Then $avName = _StringBetween($avPlayer[$n], "<name>", "</name>") If Not @error Then $Names &= $avName[0] & @CRLF EndIf Next Else MsgBox(16, "Error", "No 'Player' found in 'Players' section.") EndIf Next Else MsgBox(16, "Error", "No 'Players section' found.") EndIf MsgBox(64, "Results", "List of player names:" & @CRLF & $Names) Edited May 11, 2007 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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