Jump to content

String wildcard


Recommended Posts

Hey,

I'm writing a script for a browser game (Travian), and I'm having some trouble reading a variable number.

<a href="#" onclick='document.send.t1.value=153; return false;">(153)</a>

That's the html. It appears next to a small input box. The numerical text shows the number of troops home at the moment and so it changes quite frequently, and by clicking on it, it automatically fills the input box with the number available. Anyways, I tried making a variable with a wildcard after the "value=" so that I could search for the string. I need to read that number so I can tell if it is below a certain number, or for a few other reasons. Anyone have any ideas of how I can read that number?

Here is the small snippet of what is my best effort:

$oStr = "document.snd.t1.value=*"

Thanks in advance!

Edited by joebob764
Link to comment
Share on other sites

Alrighty I looked at the StringSplit function and yes that would work, but the problem is that I need to fetch that string from the URL. The idea is that I don't know what that number will be and so I can't search the html for that string. If I could use a wildcard instead of the number, then I could have it search. Once I have the string there are a few ways of isolating the number, it's getting that string in the first place that is my problem. Sorry for not making that clearer, and hopefully this makes sense.

Thanks!

Link to comment
Share on other sites

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd"><html>
<head>
<title>Travian nox</title>
<link rel=stylesheet type="text/css" href="new.css?w">
<link rel=stylesheet type="text/css" href="unx.css">
<script src="unx.js?w" type="text/javascript"></script>

<meta http-equiv="cache-control" content="max-age=0">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="imagetoolbar" content="no">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body onload="start()"><div id="ltop1"><div id="ltop5"><a href="dorf1.php"><img id="n1" src="img/un/a/x.gif" title="Oversikt over landsbyen"></a><a href="dorf2.php"><img id="n2" src="img/un/a/x.gif" title="Landsbyens senter"></a><a href="karte.php"><img id="n3" src="img/un/a/x.gif" title="Kart"></a><a href="statistiken.php"><img id="n4" src="img/un/a/x.gif" title="Statistikk"></a><img id="n5" src="img/un/l/m3.gif" usemap="#nb"><a href="plus.php"><img id="lplus1" src="img/no/a/plus.gif" width="80" height="100" title="Pluss-Meny"></a></div></div><map name="nb"><area shape=rect coords="0,0,35,100" href="berichte.php" title="Rapporter"><area shape=rect coords="35,0,70,100" href="nachrichten.php" title="Beskjeder"></map><div id="lmidall"><div id="lmidlc"><div id="lleft">

<a href="http://www.travian.no/"><img class="logo" src="img/no/a/travian1.gif"></a><table id="navi_table" cellspacing="0" cellpadding="0">
<tr>
<td class="menu">
<a href="http://www.travian.no/">Hjemmeside</a>
<a href="#" onclick="return Popup(0,0);">Instruksjoner</a>
<a href="spieler.php?uid=XXXXX">Profil</a><a href="logout.php">Logg ut</a><br><br><a href="http://forum.travian.no/" target="_blank">Fora</a><a href="http://www.travian.no/chat.php?chatname=nox|XXXXXX" target="_blank">Chat</a><br><br><a href="plus.php?id=3">Travian <b><font color="#71D000">P</font><font color="#FF6F0F">l</font><font color="#71D000">u</font><font color="#FF6F0F">ss</font></b></a><a href="support.php">Support</a></td>

</tr>
</table></div><div id="lmid1"><div id="lmid2"><h1>Send tropper</h1>
<form method="POST" name="snd" action="a2b.php">
<input type="hidden" name="b" value="1">
<p><table class="p1" style="width:100%"cellspacing="1" cellpadding="0"><tr><td>
<table width="100%" class="f10">
<tr>
<td width="20"><img class="unit" src="img/un/u/11.gif" title="Klubbemann" border="0" onclick="document.snd.t1.value=''; return false;"></td><td width="35"><input class="fm" type="Text" name="t1" value="" size="2" maxlength="6"></td><td class="f8"><a href="#" onclick="document.snd.t1.value=81; return false;">(81)</a></td><td width="20"><img class="unit" src="img/un/u/14.gif" title="Speider"></td><td width="35"><input class="fm" type="Text" name="t4" value="" size="2" maxlength="6"></td><td class="f8 c b"><b>(0)</b></td><td width="20"><img class="unit" src="img/un/u/17.gif" title="Rambukk"></td><td width="35"><input class="fm" type="Text" name="t7" value="" size="2" maxlength="6"></td><td class="f8 c b"><b>(0)</b></td><td width="20"><img class="unit" src="img/un/u/19.gif" title="Høvding"></td><td width="35"><input class="fm" type="Text" name="t9" value="" size="2" maxlength="6"></td><td class="f8 c b"><b>(0)</b></td></tr>


<tr>
<td width="20"><img class="unit" src="img/un/u/12.gif" title="Spydmann"></td><td width="35"><input class="fm" type="Text" name="t2" value="" size="2" maxlength="6"></td><td class="f8 c b"><b>(0)</b></td><td width="20"><img class="unit" src="img/un/u/15.gif" title="Paladin"></td><td width="35"><input class="fm" type="Text" name="t5" value="" size="2" maxlength="6"></td><td class="f8 c b"><b>(0)</b></td><td width="20"><img class="unit" src="img/un/u/18.gif" title="Katapult"></td><td width="35"><input class="fm" type="Text" name="t8" value="" size="2" maxlength="6"></td><td class="f8 c b"><b>(0)</b></td><td width="20"><img class="unit" src="img/un/u/20.gif" title="Nybyggere"></td><td width="35"><input class="fm" type="Text" name="t10" value="" size="2" maxlength="6"></td><td class="f8 c b"><b>(0)</b></td></tr>


<tr>
<td width="20"><img class="unit" src="img/un/u/13.gif" title="Øksemann"></td><td width="35"><input class="fm" type="Text" name="t3" value="" size="2" maxlength="6"></td><td class="f8 c b"><b>(0)</b></td><td width="20"><img class="unit" src="img/un/u/16.gif" title="Teutonsk Ridder"></td><td width="35"><input class="fm" type="Text" name="t6" value="" size="2" maxlength="6"></td><td class="f8 c b"><b>(0)</b></td><td colspan="6"></td></tr></table></td></tr></table></p>

<p><table width="100%" class="f10">
<tr><script language="Javascript">
<!--
var dorfnamen = new Array("02");
//-->
</script><td valign="top" width="33%">
<div class="f10"><input type="Radio" name="c" value="2" checked>Forsterkninger</div>
<div class="f10"><input type="Radio" name="c" value="3" >Angrip: Normalt</div>
<div class="f10"><input type="Radio" name="c" value="4" >Angrip: Plyndringstokt</div>
</td>

<td valign="top">
<div class="b f135">Landsby: <input class="fm" type="Text" name="dname" value="" size="10" maxlength="20" onkeyup="my_village()"></div><div><i>eller</i></div>

<div class="b f135">
X: <input class="fm" type="Text" name="x" value="45" size="2" maxlength="4">
Y: <input class="fm" type="Text" name="y" value="-142" size="2" maxlength="4">
</div>

</tr>
</table>
<p><input type="image" value="ok" border="0" name="s1" src="img/no/b/ok1.gif" width="50" height="20" onmousedown="btm1('s1','','img/no/b/ok2.gif',1)" onmouseover="btm1('s1','','img/no/b/ok3.gif',1)" onmouseup="btm0()" onmouseout="btm0()"></input></p>
</p>

</form>
</div></div></div><div id="lright1"><a href="dorf3.php"><span class="f10 c0 s7 b">Landsbyer:</span></a><table class="f10"><tr><td class="nbr"><span class="c2"></span>&nbsp; <a href="?newdid=104035&z=434588" class="active_vl">01</a></td><td class="right"><table class="dtbl" cellspacing="0" cellpadding="0">
<tr>
<td class="right dlist1">(46</td>
<td class="center dlist2">|</td>
<td class="left dlist3">-142)</td>
</tr>
</table></td></tr><tr><td class="nbr"><span></span>&nbsp; <a href="?newdid=107044&z=434588">02</a></td><td class="right"><table class="dtbl" cellspacing="0" cellpadding="0">
<tr>

<td class="right dlist1">(46</td>
<td class="center dlist2">|</td>
<td class="left dlist3">-143)</td>
</tr>
</table></td></tr></table><ul class="dl"></ul></div></div><div id="lres0">
<table align="center" cellspacing="0" cellpadding="0"><tr valign="top">
<td><img class="res" src="img/un/r/1.gif" title="Tømmer"></td>
<td id=l4 title=609>4966/9600</td>
<td class="s7"> <img class="res" src="img/un/r/2.gif" title="Leire"></td>
<td id=l3 title=516>5871/9600</td>
<td class="s7"> <img class="res" src="img/un/r/3.gif" title="Jern"></td>

<td id=l2 title=414>3221/9600</td><td class="s7"> <img class="res" src="img/un/r/4.gif" title="Korn"></td>
<td id=l1 title=-194>4760/7800</td>
<td class="s7"> &nbsp;<img class="res" src="img/un/r/5.gif" title="Bruk av korn">&nbsp;656/462</td></tr></table>
</div><div id="ltime">Kalkulasjon i <b>9</b> ms<br>Servertid: <span id="tp1" class="b">2:09:18</span> </div>
<div id="ce"></div></body>

</html>

Edit: The part that I need is in like the 6th group of large text and says

<a href="#" onclick="document.snd.t1.value=81; return false;">(81)</a> although that 81 will always change.

Edited by joebob764
Link to comment
Share on other sites

Hey, I appreciate the help. I read through your thread a few times and really don't see how it's going to help me out as my problem is that I need to get that number (which was 153 the first time and then 81 later).

However, I did try using a _StringBetween. Here is the StringBetween that I tried, and the relevant line of html

$oStr = _StringBetween ( $oHTML , "t1.value=" , "; return" )


<a href="#" onclick="document.snd.t1.value=81; return false;">(81)</a>

As far I understand things, that _StringBetween should find the 81 which lies between the "t1.value=" and the "; return". Am I missing something huge here?

Link to comment
Share on other sites

Splitting the string is easy, the problem that your facing and I have very minimal knowledge about is getting the string thus reading the source to find;

<a href="#" onclick="document.snd.t1.value=81; return false;">(81)</a>

Another approach but could be vastly slower and more cpu consuming I suppose is to write the html into a file. Then use;

FileReadLine along with StringinStr and if its true to stringsplit that line and get it that way. I dont really know if that will make sense to you as im not the greatest at explaining things.

Edited by AwAke
Link to comment
Share on other sites

Yes that would work. There's another way that would work as well ( I can go to a different view page and read it from there) but both of those would be much more time consuming. If need be I'll do one of those two but I would rather not as optimally my program should be doing this function upwards of 20-30 times a minute and so that would significantly slow things down.

A side thought. On this page, as you can see by the link, in addition to being in the HTML, the 81 (or whatever the current troop number is) is listed via text. I could do a _IEBodyReadText. The downside to this is that because on the page there are 10 input boxes, each with their own section like in the image that follows. I could then search the body text for a string between ( and ) to get the number, right? If so, is there any way I can specify which parentheses to search between? In this case I only have one group of troops at home but most of the time there will be several types present and I'll be looking for the number of a specific type.

Example

Link to comment
Share on other sites

Ah I see, perhaps doing the suggestion you mentioned reading the body of the html; I wonder then if you can search the file until you find an integer.

The value that you want should always be in the same fixed location therefore simply ignore the intergers before it and exit when it gets to say the 3rd integer found which would be the one you want.

However im unsure if the integers in the file will be classed as strings or not. As I said earlier, I cant really help you as im not very good myself =] Someone with better knowledge will be able to specify a quicker and more effecient way of doing this im sure.

Edited by AwAke
Link to comment
Share on other sites

Thanks for all the help. I continue messing around with it and trying random things out hoping to find something that worked. It turns out that the _StringBetween that I have above in post 8 works, the reason I was unable to tell was that I was trying to display it in a message box and it returns an array with entry 0 being " and entry 1 being the number. As soon as I tried to display it in an array, it worked beautifully. From there, I only have to ignore that quotation mark ( I have no idea where it came from really ) and use the Array. Viola, I have my number, no writing to an external file, no using the long cut by loading a different page. Thanks for your help and good luck on that thread of yours, sorry I can't help you there :)

Edited by joebob764
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...