Sign in to follow this  
Followers 0
sstanfie

How to search a webpage

4 posts in this topic

Hello. Although I have done a fair amount of scripting using AutoIt for a few years, I have not yet created any scripts which interact with web pages via IE.au3.

The example listed below is part of a larger script, but as you can see, I'm doing a reverse address search at http://www.whitepages.com/10583/reverse_address ...

CODE
#include <IE.au3>

$oIE = _IECreate ("http://www.whitepages.com/10583/reverse_address")

$oForm = _IEFormGetObjByName ($oIE, "reverse_address")

$oQuery1 = _IEFormElementGetObjByName ($oForm, "street")

$oQuery2 = _IEFormElementGetObjByName ($oForm, "city_zip")

_IEFormElementSetValue ($oQuery1, "1600 Pennsylvania Avenue NW")

_IEFormElementSetValue ($oQuery2, "20500")

_IEFormSubmit ($oForm)

_IELoadWait($oIE)

What I'm having a hard time figuring out is how to search the web page after the form is submitted. I want to know if there are any results and if so, what the address and phone is. I see _IEBodyReadHTML and _IEBodyReadText but I don't want to read all of this in, because it would be too difficult to try and sift through for any found results. I want to get the address into a variable (preferably 3... street, city and zip) and the phone number into another variable.

Can someone please explain how to do this?

Thank you in advance for your time.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Study this. It should get you going.

I strongly suggest using DebugBar (see my sig)

$oContainer = _IEGetObjById($oIE, "results_header")
$oResult = _IETagNameGetCollection($oContainer, "strong", 0)
ConsoleWrite(_IEPropertyGet($oResult, "innertext") & @CR)

$oContainer = _IEGetObjById($oIE, "results_single_listing")
$oResult = _IETagNameGetCollection($oContainer, "h3", 0)
ConsoleWrite(_IEPropertyGet($oResult, "innertext") & @CR)

$oResult = _IETagNameGetCollection($oContainer, "p", 0)
ConsoleWrite(_IEPropertyGet($oResult, "innertext") & @CR)

$oResult = _IETagNameGetCollection($oContainer, "p", 1)
ConsoleWrite(_IEPropertyGet($oResult, "innertext") & @CR)

Dale

Edit: missing parens

Edited by DaleHohm

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

Yes, DebugBar is awesome. It really makes all of this easier.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

This was very helpful. Thank you.

And wow, DebugBar is great.

Study this. It should get you going.

I strongly suggest using DebugBar (see my sig)

$oContainer = _IEGetObjById($oIE, "results_header")
$oResult = _IETagNameGetCollection($oContainer, "strong", 0)
ConsoleWrite(_IEPropertyGet($oResult, "innertext") & @CR)

$oContainer = _IEGetObjById($oIE, "results_single_listing")
$oResult = _IETagNameGetCollection($oContainer, "h3", 0)
ConsoleWrite(_IEPropertyGet($oResult, "innertext") & @CR)

$oResult = _IETagNameGetCollection($oContainer, "p", 0)
ConsoleWrite(_IEPropertyGet($oResult, "innertext") & @CR)

$oResult = _IETagNameGetCollection($oContainer, "p", 1)
ConsoleWrite(_IEPropertyGet($oResult, "innertext") & @CR)

Dale

Edit: missing parens

Edited by sstanfie

Share this post


Link to post
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
Sign in to follow this  
Followers 0