Jump to content

Return a part of a content from webpage


Recommended Posts

Hi there,

I am new to this community and i am trying to learn more using this cool autoIT language. I'm implementing my own function to return a part of a content ( or table ) from a webpage.

Specifically, I'm trying to get the result from http://www.ip2location.com/xxx.xxx.xxx.xxx where xxx is your IP address. I don't want to return the whole result table. Which im trying to focus on is to return the ZIP Code of my IP Address.

I'm trying to catch it with:

$RealZip = _IEGetObjByName( $oIE2, "dgLookup__ctl2_lblIZIPCode" )   
    $Zip = _IEFormElementGetValue( $RealZip )

I would like to return the ZIP result into the $Zip. But it seems not right and unfinished.

Please help or provide me some suggestion in order to solve this problem.

Thank you so much and have a great day!

Link to comment
Share on other sites

Local $url = "http://www.ip2location.com/70.86.96.219"

Local $page = InetRead($url, 1)

Local $pattern = '(?i)(?s)lblIZIPCode">(.*?)</span>'

Local $aRet = StringRegExp(BinaryToString($page), $pattern, 3)

If IsArray($aRet) Then MsgBox(0, $url, $aRet[0])

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Link to comment
Share on other sites

That works perfectly for me. Thanks a lot!

PS: can you spend a little time explain this line for me please? I read the definition of StringRegExp but it seems like doesn't help

Local $aRet = StringRegExp(BinaryToString($page), $pattern, 3)
Link to comment
Share on other sites

npploveyou - Welcome to the AutoIt Forums

In simplified terms, that particular line looks for a match of a starting string and an ending string.

Whatever is in between the two, returns what is found in the array $aRet. In this case, the zipcode.

StringRegExp is not something you learn overnight. I'm still learning it myself!

For more information:

http://www.autoitscript.com/autoit3/docs/functions/StringRegExp.htm

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

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