Jump to content

reading source code


Recommended Posts

  • Moderators

I know how to get the source code of a page, but i don't know how to read a specific value.

So for example I've got in the mid of line 15 a number I want to use, how to get only this number. :lmao:

I hope getting help soon. :ph34r:

Space-tiger

Find the tags that the items you want to find are between and use this udf:
Func _SRE_Between($s_String, $s_Start, $s_End, $bCaseInsensitive = False)
    Local $sCaseFlag = ""
    If $bCaseInsensitive Then $sCaseFlag = "(?i)"
    $a_Array = StringRegExp($s_String, '(?s)' & $sCaseFlag & $s_Start & '(.*?)' & $s_End, 3)
    If IsArray($a_Array) Then Return $a_Array
    Return SetError(1, 0, 0)
EndFunc;==>_SRE_Between
Edit:Requires Beta 3.2.1.8 or higher. Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Find the tags that the items you want to find are between and use this udf:

Func _SRE_Between($s_String, $s_Start, $s_End, $bCaseInsensitive = False)
    Local $sCaseFlag = ""
    If $bCaseInsensitive Then $sCaseFlag = "(?i)"
    $a_Array = StringRegExp($s_String, '(?s)' & $sCaseFlag & $s_Start & '(.*?)' & $s_End, 3)
    If IsArray($a_Array) Then Return $a_Array
    Return SetError(1, 0, 0)
EndFunc;==>_SRE_Between
Edit:Requires Beta 3.2.1.8 or higher.

Ok thx gonna try it.

Btw. it would be nice if you could give an explanation to the variables used :lmao:

I got "<td id=l1 title=1200>1929/17600</td>" in a line. What has to be declared to which variable?

Edited by Space-tiger
Link to comment
Share on other sites

  • Moderators

Ok thx gonna try it.

Btw. it would be nice if you could give an explanation to the variables used :lmao:

I got "<td id=l1 title=1200>1929/17600</td>" in a line. What has to be declared to which variable?

The variables aren't explained well enough in the example?

#include <array.au3>
$string = "<td id=l1 title=1200>1929/17600</td>"
$return = _SRE_Between($string, "<td id=l1 title=1200>", "</td>", True)
MsgBox(64, 'Info', $return[0])

Func _SRE_Between($s_String, $s_Start, $s_End, $bCaseInsensitive = False)
    Local $sCaseFlag = ""
    If $bCaseInsensitive Then $sCaseFlag = "(?i)"
    $a_Array = StringRegExp($s_String, '(?s)' & $sCaseFlag & $s_Start & '(.*?)' & $s_End, 3)
    If IsArray($a_Array) Then Return $a_Array
    Return SetError(1, 0, 0)
EndFunc;==>_SRE_Between

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Why does he return always "0"?

#include <INet.au3>
#include <array.au3>

$string = _INetGetSource ( FileReadLine ("Config.txt", 1) )
$return = _SRE_Between($string,"<td id=l1 title=1200>", "</td>", True)
MsgBox(64, 'Info', $return)

Func _SRE_Between($s_String, $s_Start, $s_End, $bCaseInsensitive = False)
Local $sCaseFlag = ""
If $bCaseInsensitive Then $sCaseFlag = "(?i)"
$a_Array = StringRegExp($s_String, '(?s)' & $sCaseFlag & $s_Start & '(.*?)' & $s_End, 3)
If IsArray($a_Array) Then Return $a_Array
Return SetError(1, 0, 0)
EndFunc;==>_SRE_Between

Config.txt contains in first line the url of a souce code that contains somewhere <td id=l1 title=1200>10239/17600</td> but the 10239/17600 changes all the time that's why I wanna read it.

But even if I change MsgBox(64, 'Info', $return) to MsgBox(64, 'Info', $return[0]) he says Subscript used with non-Array variable.:

MsgBox(64, 'Info', $return[0])

MsgBox(64, 'Info', $return^ ERROR

I'd be very happy if you could help me! :lmao:

Link to comment
Share on other sites

  • Moderators

Do you have all the info neccessary to help you debug? Like the FileReadLine() << we have no idea what is in that text file, or what site you are trying to parse.

Even the link to the site would help.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Do you have all the info neccessary to help you debug? Like the FileReadLine() << we have no idea what is in that text file, or what site you are trying to parse.

Even the link to the site would help.

Ok, it's http://s3.travian.com/build.php?id=1 but you won't be able to see it without an account.

Do you mean that I have to store the source code in a file and then read a single line?

AutoIt can't find what I seek in a whole text ?!

PS:

You must have cookies activated to login, that's why I tell my program before to login and call this page in background.

Maybe the server doesn't permit autoit to read the source code as it has no cookies.

Link to comment
Share on other sites

  • Moderators

Ok, it's http://s3.travian.com/build.php?id=1 but you won't be able to see it without an account.

Do you mean that I have to store the source code in a file and then read a single line?

AutoIt can't find what I seek in a whole text ?!

PS:

You must have cookies activated to login, that's why I tell my program before to login and call this page in background.

Maybe the server doesn't permit autoit to read the source code as it has no cookies.

Have you tried to debug it at all?

$string = _INetGetSource ( FileReadLine ("Config.txt", 1) )
MsgBox(0, 'Should return the source', $string)
?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

Hmm, care to post it? Or do we just play the guessing game?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

You will see that my proxomitron changes the code a bit, that's why I'd like to let him search for the value in the whole text.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd"><html>
<head>

<!-- <Proxomitron filter="Prox: Start-Filterskript einfuegen"> -->
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript">
var ProxSuccessStartCode="HeadGeladen"; var ProxSuccessEndCode=false; var ProxJSVer="Head:3.1.0,"; if(!window.document.ProxSK_write){window.document.ProxSK_write=window.document.write;} if(!window.ProxSK_windowSetTimeout){window.ProxSK_windowSetTimeout=window.setTimeout;}
var ProxConfSC = "GoogleSpamRedir,FktWinMovRes,FktWinFocBlu,EHPageUnload,EHMouseDownUp,WOCActive,WOCAllowonclick,WOCForceCon,WOCNotifOpt,";
</script>
<link rel="stylesheet" type="text/css" href="http://local.ptron/ProxCSS.css" charset="ISO-8859-1" /> <script type="text/javascript" src="http://local.ptron/ProxJSStart.js" charset="ISO-8859-1"></script>
<!-- </Proxomitron> -->

<title>Travian</title>
<link rel=stylesheet type="text/css" href="un3.css">
<script src="en3.js" type=text/javascript></script>

<meta http-equiv="imagetoolbar" content="no">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body onload="start()"><div class="div1"></div><map name="nb"><area shape=rect coords="0,0,35,100" href="berichte.php" title="Reports"><area shape=rect coords="35,0,70,100" href="nachrichten.php" title="Messages"></map><div class="div2">
<a href="dorf1.php" id="n1"><img class="fl2" src="img/un/l/d1.gif" width="70" height="100" border="0" onmouseover="this.className='fl1'" onmouseout="this.className='fl2'" title="Village overview"></a><a href="dorf2.php" id="n2"><img class="fl2" src="img/un/l/d2.gif" width="70" height="100" border="0" onmouseover="this.className='fl1'" onmouseout="this.className='fl2'" title="Village center"></a><a href="karte.php" id="n3"><img class="fl2" src="img/un/l/ka.gif" width="70" height="100" border="0" onmouseover="this.className='fl1'" onmouseout="this.className='fl2'" title="Map"></a><a href="statistiken.php" id="n4"><img class="fl2" src="img/un/l/st.gif" width="70" height="100" border="0" onmouseover="this.className='fl1'" onmouseout="this.className='fl2'" title="Statistics"></a><img src="img/un/l/m4.gif" width="70" height="100" border="0" usemap="#nb">
</div>

<div class="plus"><a href="plus.php"><img src="img/en/a/plus.gif" width="80" height="100" border="0" title="Plus menu"></a></div>
<img src="img/un/a/x.gif" width="1" height="90" border="0">

<table cellspacing="0" cellpadding="0"><tr valign="top">
<td class="s1">
<a href="http://www.travian.com/"><img src="img/en/a/travian0.gif" width="116" height="60" border="0"></a>

<table style="height:auto" width="116" cellspacing="0" cellpadding="0">
<tr>

<td class="menu">
<a href="http://www.travian.com/">Homepage</a>
<a href="#" onclick="Popup(0,0)">Instructions</a>
<a href="spieler.php?uid=7773">Profile</a><a href="logout.php">Logout</a><br><br>
<a href="http://forum.travian.com/" target="_blank">Forum</a>
<a href="http://www.travian.com/chat/" 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">s</font></b></a>

<!--<a href="mobile.php">Travian <i><font color="#71D000"><b>Mobile</b></font></i></a>-->
</td>
</tr>
</table>

<td class="s2"><img src="img/un/a/w.gif" width="1" height="10" border="0"></td>
<td class="s3"><h1><b>Woodcutter level 9</b></h1>
<p class="f10">The woodcutter cuts down trees in order to produce wood. The further you extend the woodcutter the more wood is produced by him.</p><table width="100%" cellspacing="4" cellpadding="0">
<tr>
<td width="200"><font size="-1">Current production:</font></td>
<td><font size="-1"><b>435</b> per hour</font></td>

</tr>

<tr>
<td width="200"><font size="-1">Production at level 10:</font></td>
<td><font size="-1"><b>600</b> per hour</font></td>
</tr>
</table><p><b>Costs</b> for the upgrading to level  10:
<table class="f10"><tr><td><img src="img/un/r/1.gif" width="18" height="12">4040 | <img src="img/un/r/2.gif" width="18" height="12">10105 | <img src="img/un/r/3.gif" width="18" height="12">5050 | <img src="img/un/r/4.gif" width="18" height="12">6060 | <img src="img/un/r/5.gif" width="18" height="12">2 | <img src="img/un/a/clock.gif" width="18" height="12"> 2:00:00</td></tr></table>

<span class="c">Too few resources</span></p></td>
<td class="s2"><img src="img/un/a/w.gif" width="1" height="10" border="0"></td>
</tr>
</table><div class="div4">
<table align="center" cellspacing="0" cellpadding="0"><tr class="f10" valign="top">
<td><img src="img/un/r/1.gif" width="18" height="12" border="0" title="Lumber"></td>
<td id=l1 title=1470>4524/21400</td>
<td class="s7"> <img src="img/un/r/2.gif" width="18" height="12" title="Clay"></td>
<td id=l2 title=1740>1381/21400</td>
<td class="s7"> <img src="img/un/r/3.gif" width="18" height="12" title="Iron"></td>
<td id=l3 title=1200>3491/21400</td><td class="s7"> <img src="img/un/r/4.gif" width="18" height="12" title="Crop"></td>

<td id=l4 title=694>4724/11800</td>
<td class="s7">  <img src="img/un/r/5.gif" width="18" height="12" alt="Crop usage"> 731/1425</td></tr></table>
</div><div id="ba" style="position:absolute; z-index:5; border: 0px solid #000000; left: 700px; top: 100px">
<b class="f10"><a href="dorf3.php"><span class="f10 c0 s7">Villages:</span></a></b><table class="f10"><tr><td nowrap><span></span>  <a href="?newdid=24007&id=1">I Methanolia</a></td><td width="73" align="right"><table width="73" cellspacing="0" cellpadding="0" class="f8">
<tr>
<td width="35" align="right" nowrap>(91</td>
<td width="3" align="center">|</td>
<td width="35" align="left" nowrap>28)</td>

</tr>
</table></td></tr><tr><td nowrap><span class="c2"></span>  <a href="?newdid=10327&id=1" class="active_vl">II Ethanolia</a></td><td width="73" align="right"><table width="73" cellspacing="0" cellpadding="0" class="f8">
<tr>
<td width="35" align="right" nowrap>(86</td>
<td width="3" align="center">|</td>
<td width="35" align="left" nowrap>23)</td>
</tr>
</table></td></tr></table><br></div></div><div class="div3">Calculation in <b>11</b> ms<br>Server time: <b><span id=tp1>17:12:51</span></b> <p class="f8">E:0</p></div>

<div id="ce"></div>



<!-- <Proxomitron filter="Prox: End-Filterskript einfuegen"> -->
<script language="Javascript" type="text/javascript" src="http://local.ptron/ProxJSEnd.js" charset="ISO-8859-1"></script>
<!-- </Proxomitron> -->
</body>
</html>
Link to comment
Share on other sites

  • Moderators

Use...

ClipPut(_InetGetSource($URLHERE))
Then it will be in your clip board and you can post what exactly SRE would be seeing.

Edit:

Also post exactly what it is you ar trying to find, I couldn't find "tile" anywhere in that text... If the browser messed it up that bad then :lmao:

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

I executed the script and here's the paste:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"

"http://www.w3.org/TR/html4/strict.dtd"><html>

<head>

<title>Travian</title>

<link rel=stylesheet type="text/css" href="un3.css">

<script src="en3.js" type=text/javascript></script>

<meta http-equiv="imagetoolbar" content="no">

<meta http-equiv="content-type" content="text/html; charset=UTF-8">

</head>

<body onload="start()"><div class="div1"></div><map name="nb"><area shape=rect coords="0,0,35,100" href="berichte.php" title="Reports"><area shape=rect coords="35,0,70,100" href="nachrichten.php" title="Messages"></map><div class="div2">

<a href="dorf1.php" id="n1"><img class="fl2" src="img/un/l/d1.gif" width="70" height="100" border="0" onmouseover="this.className='fl1'" onmouseout="this.className='fl2'" title="Village overview"></a><a href="dorf2.php" id="n2"><img class="fl2" src="img/un/l/d2.gif" width="70" height="100" border="0" onmouseover="this.className='fl1'" onmouseout="this.className='fl2'" title="Village center"></a><a href="karte.php" id="n3"><img class="fl2" src="img/un/l/ka.gif" width="70" height="100" border="0" onmouseover="this.className='fl1'" onmouseout="this.className='fl2'" title="Map"></a><a href="statistiken.php" id="n4"><img class="fl2" src="img/un/l/st.gif" width="70" height="100" border="0" onmouseover="this.className='fl1'" onmouseout="this.className='fl2'" title="Statistics"></a><img src="img/un/l/m3.gif" width="70" height="100" border="0" usemap="#nb">

</div>

<div class="plus"><a href="plus.php"><img src="img/en/a/plus.gif" width="80" height="100" border="0" title="Plus menu"></a></div>

<img src="img/un/a/x.gif" width="1" height="90" border="0">

<table cellspacing="0" cellpadding="0"><tr valign="top">

<td class="s1">

<a href="http://www.travian.com/"><img src="img/en/a/travian0.gif" width="116" height="60" border="0"></a>

<table style="height:auto" width="116" cellspacing="0" cellpadding="0">

<tr>

<td class="menu">

<a href="http://www.travian.com/">Homepage</a>

<a href="#" onclick="Popup(0,0)">Instructions</a>

<a href="spieler.php?uid=7773">Profile</a><a href="logout.php">Logout</a><br><br>

<a href="http://forum.travian.com/" target="_blank">Forum</a>

<a href="http://www.travian.com/chat/" 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">s</font></b></a>

<!--<a href="mobile.php">Travian <i><font color="#71D000"><b>Mobile</b></font></i></a>-->

</td>

</tr>

</table>

<td class="s2"><img src="img/un/a/w.gif" width="1" height="10" border="0"></td>

<td class="s3"><h1><b>Woodcutter level 9</b></h1>

<p class="f10">The woodcutter cuts down trees in order to produce wood. The further you extend the woodcutter the more wood is produced by him.</p><table width="100%" cellspacing="4" cellpadding="0">

<tr>

<td width="200"><font size="-1">Current production:</font></td>

<td><font size="-1"><b>435</b> per hour</font></td>

</tr>

<tr>

<td width="200"><font size="-1">Production at level 10:</font></td>

<td><font size="-1"><b>600</b> per hour</font></td>

</tr>

</table><p><b>Costs</b> for the upgrading to level 10:

<table class="f10"><tr><td><img src="img/un/r/1.gif" width="18" height="12">4040 | <img src="img/un/r/2.gif" width="18" height="12">10105 | <img src="img/un/r/3.gif" width="18" height="12">5050 | <img src="img/un/r/4.gif" width="18" height="12">6060 | <img src="img/un/r/5.gif" width="18" height="12">2 | <img src="img/un/a/clock.gif" width="18" height="12"> 2:00:00</td></tr></table>

<span class="c">Too few resources</span></p></td>

<td class="s2"><img src="img/un/a/w.gif" width="1" height="10" border="0"></td>

</tr>

</table><div class="div4">

<table align="center" cellspacing="0" cellpadding="0"><tr class="f10" valign="top">

<td><img src="img/un/r/1.gif" width="18" height="12" border="0" title="Lumber"></td>

<td id=l1 title=1470>2859/21400</td>

<td class="s7"> <img src="img/un/r/2.gif" width="18" height="12" title="Clay"></td>

<td id=l2 title=1740>1344/21400</td>

<td class="s7"> <img src="img/un/r/3.gif" width="18" height="12" title="Iron"></td>

<td id=l3 title=1200>3199/21400</td><td class="s7"> <img src="img/un/r/4.gif" width="18" height="12" title="Crop"></td>

<td id=l4 title=691>5173/11800</td>

<td class="s7"> &nbsp;<img src="img/un/r/5.gif" width="18" height="12" alt="Crop usage">&nbsp;734/1425</td></tr></table>

</div><div id="ba" style="position:absolute; z-index:5; border: 0px solid #000000; left: 700px; top: 100px">

<b class="f10"><a href="dorf3.php"><span class="f10 c0 s7">Villages:</span></a></b><table class="f10"><tr><td nowrap><span></span>&nbsp; <a href="?newdid=24007&id=1">I Methanolia</a></td><td width="73" align="right"><table width="73" cellspacing="0" cellpadding="0" class="f8">

<tr>

<td width="35" align="right" nowrap>(91</td>

<td width="3" align="center">|</td>

<td width="35" align="left" nowrap>28)</td>

</tr>

</table></td></tr><tr><td nowrap><span class="c2"></span>&nbsp; <a href="?newdid=10327&id=1" class="active_vl">II Ethanolia</a></td><td width="73" align="right"><table width="73" cellspacing="0" cellpadding="0" class="f8">

<tr>

<td width="35" align="right" nowrap>(86</td>

<td width="3" align="center">|</td>

<td width="35" align="left" nowrap>23)</td>

</tr>

</table></td></tr></table><br></div></div><div class="div3">Calculation in <b>14</b> ms<br>Server time: <b><span id=tp1>17:41:17</span></b> <p class="f8">E:0</p></div>

<div id="ce"></div></body>

</html>

Edit: I marked the line to read big.

Edited by Space-tiger
Link to comment
Share on other sites

  • Moderators

Do you want that "Specific" string "1470" or all of them that are like that?

Edit:

I'll assume you're doing this on an l1/l2/l3 etc basis, this is just for l1

$return = _SRE_Between($string,"<td id=l1 title=\d{1,5}>", "</td>", True)oÝ÷ Ù8b²+"*.Á©íjYméußÛ?Ûlÿ}ý±ëjëh×6$return = _SRE_Between($string,"<td id=l\d{1,3} title=\d{1,5}>", "</td>", True)
Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Do you want that "Specific" string "1470" or all of them that are like that?

Edit:

I'll assume you're doing this on an l1/l2/l3 etc basis, this is just for l1

$return = _SRE_Between($string,"<td id=l1 title=\d{1,5}>", "</td>", True)oÝ÷ Ù8b²+"*.Á©íjYméußÛ?Ûlÿ}ý±ëjëh×6$return = _SRE_Between($string,"<td id=l\d{1,3} title=\d{1,5}>", "</td>", True)oÝ÷ Ûú®¢×Á©íÖi¦i©e}Ãjëh×6#include <INet.au3>
#include <array.au3>
#include <_SRE_Between.au3> ;Contains the function

$string = _INetGetSource ("http://s3.travian.com/build.php?id=1")
$return = _SRE_Between($string,"<td id=l\d{1,4} title=\d{1,5}>", "</td>", True)
MsgBox(64, 'Info', $return[0])

Doesn't work, shows error. Without [0] it shows 0

Link to comment
Share on other sites

  • Moderators

I want it aaaaaaaalll! :lmao:

#include <INet.au3>
#include <array.au3>
#include <_SRE_Between.au3> ;Contains the function

$string = _INetGetSource ("http://s3.travian.com/build.php?id=1")
$return = _SRE_Between($string,"<td id=l\d{1,4} title=\d{1,5}>", "</td>", True)
MsgBox(64, 'Info', $return[0])oÝ÷ Ø:²}ý·
+ÈhÂÇ«®ÖØhºÝ"¶ÈhÂÍ?ªê-zé캷ºÇ¶¬¢êÜ{*.¦º/׶^²Ø­jwbµ·hzÏÛÂäm«v߶­"¯zz0k*µë-x+axǺÚ"µÍÚ[ÛYH   ÒS]]LÉÝÂÚ[ÛYH Ø^K]LÉÝÂÚ[ÛYH ×ÔÔWÐ]ÙY[]LÉÝÈÐÛÛZ[ÈH[Ý[ÛÌÍÜÝ[ÈHÒS]Ù]ÛÝÙH
    ][ÝÚËÜÌË]X[ÛÛKØZ[ÚYLI][ÝÊBÌÍÜ]HÔÔWÐ]ÙY[  ÌÍÜÝ[Ë ][ÝÉÝY[  ÌLÙÌK
H]OIÌLÙÌK
_IÝÉ][ÝË    ][ÝÉËÝ  ÝÉ][ÝËYJBÐ^QÜ^J   ÌÍÜ] ÌÎNÐ[Ý[ ÌÎNÊ
If you don't get a message box with all of them found, then they don't exist in what you were looking for.

You may want to just do a _InetGet() ... put it to a file + FileRead for the $string and then use _SRE between.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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...