Jump to content

[Solved] How to grab this infos from file? (Or what is the right way?)


Fire
 Share

Recommended Posts

Hi to all Great Autoit Community.

So, i need help please help me in this to properly figure it out.

I`m trying to create small program for Reverse Ip.

So this is my script:(Snippet from it)

case $Button1
$useragent=HttpSetUserAgent("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.3) Gecko/20100401 MRA 5.6 (build 03278) Firefox/3.6.3 GTB7.0")
            InetGet("onlineser5viceurlgoeshere.com/lookup.php?addr="&GUICtrlRead($Input1)&"&x=0&y=0",@ScriptDir & _
            "\file.html")
            MsgBox(64,"","End")
;EOF Snipped From Autoitscript code

When script finished file.html (result of lookup) exist in @Scriptdir)

I need extract from file.html this entries:

Please note that this infos dynamically changes from another iP Reverse Lookup and it may be 100% different from this:

I know may be i`m unclear .Because my English bad and i cannot properly say my question.

reveripedsitename.com

IP  xx.xx.xxx.x
CONTINENT CODE  NA
COUNTRY CODE    US
COUNTRY NAME    United States
REGION CODE     TX
REGION NAME     Texas
CITY    Houston
LATITUDE    29.7523
LONGITUDE   -95.367
PROVIDER (ORG)  AS21844

And i know that i need grab this infos from this snipped of html page (from downloaded file.html file)

So, my question what is the right way grab this info from file.html ?

_stringbetween() ? or i need StringRegExp() or filereadline() with assosiated with _stringmid() ?

Thank you very much And Thanks in advance again.

Below snipped from file.html file:

<div class='search_result'>
<div class='search_title'>sitenamegoeshereinotput.com</div><br>
<div class='search_data'>
<table class='table1' >
<tr><td class='td_var'>IP </td><td class='td_val'><a href=somelurlhere=xx.xx.xxx.x'>xx.xx.xxx.x</a></td></tr>
<tr>
<td class='td_var'>CONTINENT CODE</td>

<td class='td_val'>NA</td>
</tr>
<tr>
<td class='td_var'>COUNTRY CODE</td>
<td class='td_val'>US</td>
</tr>
<tr>
<td class='td_var'>COUNTRY NAME</td>
<td class='td_val'>United States</td>
</tr>
<tr>
<td class='td_var'>REGION CODE</td>

<td class='td_val'>TX</td>
</tr>
<tr>
<td class='td_var'>REGION NAME</td>
<td class='td_val'>Texas</td>
</tr>
<tr>
<td class='td_var'>CITY</td>
<td class='td_val'>Houston</td>
</tr>
<tr>
<td class='td_var'>LATITUDE</td>

<td class='td_val'>29.7523</td>
</tr>
<tr>
<td class='td_var'>LONGITUDE</td>
<td class='td_val'>-95.367</td>
</tr>
<tr>
<td class='td_var'>PROVIDER (ORG)</td>
<td class='td_val'>AS21844</td>
</tr>

I think this would be right way:

Get html tags and infos :

<div class='search_result'>
--------------------------
-------------------------
------------------
------------------------------
</table>

and then create _IECreateEmbedded () for new file which contains extracted tags+infos then display all info in GUI.

But how to get this diapason of tags?

edit:grammatical mistakes :idea:

Edited by Sh3llC043r
[size="5"] [/size]
Link to comment
Share on other sites

Which information exactly do you need?

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Ok sorry jchd.

I know i`m unclear.

I think i need :

Get html tags include infos :

<div class='search_result'>
--------------------------
-------------------------
------------------
------------------------------
</table>

from file.html file.

and then create _IECreateEmbedded () for new file which contains extracted tags+infos then display all info in GUI.

But how to get this diapason of tags include infos?

[size="5"] [/size]
Link to comment
Share on other sites

$sStr = FileRead(@ScriptDir & "\file.html")
$aInfo = StringRegExp(StringRegExpReplace($sStr, "(?i)(?s)(?U).*<div class=.?search_data.?>(.+)</div>.*", "$1"), "(?i)<td.+?>(.+?)</td>", 3)
If NOT @Error Then
    $sRtn = ""
    For $i = 0 To Ubound($aInfo) -2 Step 2
        $aInfo[$i +1] = StringRegExpReplace($aInfo[$i+1], "<.+?>", "")
        $sRtn &= $aInfo[$i] & " = " & $aInfo[$i+1] & @CRLF
    Next

    MsgBox(0, "Result", $sRtn
EndIf

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Glad it works but how you display the result is up to you. BTW if you look through Chat, I think I posted a complete script for doing exactly the same as you are doing with a GUI.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Thanks again GEOSoft.

Here is:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <File.au3>
#include <GuiEdit.au3>
Dim $avarray
#Region ### START Koda GUI section ### Form=Form1.kxf
$Form1 = GUICreate("", 636, 750, 210, 122)
$Input1 = GUICtrlCreateInput("Ip Or Domain Name Goes Here", 176, 144, 273, 21)
$Button1 = GUICtrlCreateButton("Get Result", 224, 216, 137, 33, $WS_GROUP)
$Edit1 = GUICtrlCreateEdit("", 88, 328, 473, 369)
GUICtrlSetData(-1, "")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            GUICtrlSetData($Edit1,"")

            $useragent=HttpSetUserAgent("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.3) Gecko/20100401 MRA 5.6 (build 03278) Firefox/3.6.3 GTB7.0")
            InetGet("http://my-addr.com/reverse-lookup-domain-hostname/free-reverse-ip-lookup-service/reverse_lookup.php?addr="&GUICtrlRead($Input1)&"&x=0&y=0",@TempDir & _
            "\file.html")





            $sStr = FileRead(@TempDir & "\file.html")
$aInfo = StringRegExp(StringRegExpReplace($sStr, "(?i)(?s)(?U).*<div class=.?search_data.?>(.+)</div>.*", "$1"), "(?i)<td.+?>(.+?)</td>", 3)
If NOT @Error Then
    $sRtn = ""
    For $i = 0 To Ubound($aInfo) -2 Step 2
    $aInfo[$i +1] = StringRegExpReplace($aInfo[$i+1], "<.+?>", "")
    $sRtn &= $aInfo[$i] & " = " & $aInfo[$i+1] & @CRLF

    Next
FileWrite(@TempDir&"\data4.txt",$sRtn)
    ;MsgBox(0, "Result", $sRtn)

    _FileReadToArray(@TempDir&"\data4.txt",$avarray)
    RunWait("cmd.exe /c " & "del /q " & @TempDir&"\data4.txt" & "&& " & "del /q " & @TempDir&"\file.html",@ScriptDir,@SW_HIDE)

    For $i=1 To $avarray[0]
        _GUICtrlEdit_AppendText($Edit1,$avarray[$i] & @CRLF)
        Next


EndIf

    EndSwitch
WEnd

Thanks so much again to all.

Edited by Sh3llC043r
[size="5"] [/size]
Link to comment
Share on other sites

You could have saved yourself some trouble by just using what I gave you and then forgrt about writing to a file and forget about GUICtrlEdit_AppendText().

Where I have the MsgBox, replace it with

GUICtrlSetData($Edit1, $sRtn)

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

You could have saved yourself some trouble by just using what I gave you and then forgrt about writing to a file and forget about GUICtrlEdit_AppendText().

Where I have the MsgBox, replace it with

GUICtrlSetData($Edit1, $sRtn)

Thanks GEOSoft.

Yeah you are right.This is not completed script and i`m working on it to add more stuff only reason using

_GUICtrlEdit_AppendText()

And yes your way rescued me and Helped me 99 %.

Thank you again GEOSoft and jchd

[size="5"] [/size]
Link to comment
Share on other sites

There are two ways to do it: either use the _IE functions, a clean way if you know what you're searching for (your case), or use the dirty path using regexps. I assume the answer for geolocation of a single IP is short, so you can have it loaded in one variable and extract the whole stuff needed in one shot.

Got distracted elsewhere and I see that you're home. I did nothing on this one!

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

There are two ways to do it: either use the _IE functions, a clean way if you know what you're searching for (your case), or use the dirty path using regexps. I assume the answer for geolocation of a single IP is short, so you can have it loaded in one variable and extract the whole stuff needed in one shot.

Got distracted elsewhere and I see that you're home. I did nothing on this one!

jchd yeah solved.Thanks to you too for response.Really my sincerely Thank Guys.:idea:

[size="5"] [/size]
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...