Jump to content

_IEAttach on a new webpage


Recommended Posts

I hope someone might be able to put me out of my coding misery.

My overall goal: To batch-download education-related PDF files relating to No Child Left Behind. The starting point is here: https://rptsvr1.tea.texas.gov/ayp/2005/campus.srch.html. But I need to navigate through several webpages to commence a download.

Work completed: I've been able to successfully automate the initial webpage by checking the radio button 'Campus by Region Number' and clicking the 'Continue' button:

$o_IE = _IECreate()
_IENavigate ($o_IE, "https://rptsvr1.tea.texas.gov/ayp/2005/campus.srch.html")
$o_Search = _IEFormGetObjByName ($o_IE, "camp")
$o_Next = _IEGetObjByName($o_IE, "submit")
_IEFormElementRadioSelect($o_Search, "regnum", "search", 1, "byValue")
_IEAction($o_Next, "click")

On the next webpage, I need to select a region from the option box and click continue. I plan to hard code the selection for now and worry about looping over all regions later.

My specific problem: I need to point AutoIt to the form on the new webpage (the form itself appears to be unnamed, but the option box is called 'regnback'). I think _IEAttach is the right way to point AutoIt to the new webpage. However, I cannot get the command to work. I tried this code:

$o_IEC = _IEAttach ("2005 Campus AYP Report", "windowtitle")

It returns an error: _IESTATUS_NoMatch. I tried the "title" option too, and some text from the body of the page with the "text" option, but no joy.

My apologies for what I'm sure is a very basic question; unfortunately several hours on Google failed to point me in the right direction. This thread seemed most similar to my problem. In any case, thanks for taking a look.

 

Link to comment
Share on other sites

Look, I've been trying to wrap my head around your problem, however, the source code of the webpage you're having the issue with is truly horrible.

The only thing that I could manage to do was find the 2nd <option> tag by searching for value, but I don't think clicking it is possible. You might want to try an alternative, for example, MouseClick() might do the trick. That requires for the browser window to be focused and but I doubt there's another way to do this. Don't take my word for it since I'm not really an expert, it's just my advice.

Here's the most I could do:

#include <IE.au3>

$o_IE = _IECreate()
_IENavigate ($o_IE, "https://rptsvr1.tea.texas.gov/ayp/2005/campus.srch.html")
$o_Search = _IEFormGetObjByName ($o_IE, "camp")
$o_Next = _IEGetObjByName($o_IE, "submit")
_IEFormElementRadioSelect($o_Search, "regnum", "search", 1, "byValue")
_IEAction($o_Next, "click")
_IELoadWait($o_IE)
$o_IEC = _IEAttach ("2005 Campus AYP Report", "windowtitle")
$oOptions = _IETagnameGetCollection($o_IE, "option")

For $Option in $oOptions
    If $Option.value = 02 Then
        MsgBox(0,0, "Found option!")
        _IEAction ($Option, "click") ; Doesn't click it anyway :(
        ExitLoop
    EndIf
 Next

 

Link to comment
Share on other sites

You should be able to just parse the HTML to get the required values and then use InetGet to download the file. For example:

The URL for one of the files is https://rptsvr1.tea.texas.gov/cgi/sas/broker?_service=marykay&_program=perfrept.perfmast.sas&prgopt=2005%2Fayp%2Fpdfcx.sas&year4=2005&year2=05&topic=ayp&gifname=t_05aypcamp&title=AYP%2BReport&level=Campus&search=campback&sublevel=SUBLEVEL&ptype=PTYPE&campback=108902001+

Instead of traversing the website with the IE functions, just use the desired campback value in the URL and download the file.

 

Link to comment
Share on other sites

1 hour ago, ProgrammerKid said:

Look, I've been trying to wrap my head around your problem, however, the source code of the webpage you're having the issue with is truly horrible.

The only thing that I could manage to do was find the 2nd <option> tag by searching for value, but I don't think clicking it is possible. You might want to try an alternative, for example, MouseClick() might do the trick. That requires for the browser window to be focused and but I doubt there's another way to do this. Don't take my word for it since I'm not really an expert, it's just my advice.

Here's the most I could do:

#include <IE.au3>

$o_IE = _IECreate()
_IENavigate ($o_IE, "https://rptsvr1.tea.texas.gov/ayp/2005/campus.srch.html")
$o_Search = _IEFormGetObjByName ($o_IE, "camp")
$o_Next = _IEGetObjByName($o_IE, "submit")
_IEFormElementRadioSelect($o_Search, "regnum", "search", 1, "byValue")
_IEAction($o_Next, "click")
_IELoadWait($o_IE)
$o_IEC = _IEAttach ("2005 Campus AYP Report", "windowtitle")
$oOptions = _IETagnameGetCollection($o_IE, "option")

For $Option in $oOptions
    If $Option.value = 02 Then
        MsgBox(0,0, "Found option!")
        _IEAction ($Option, "click") ; Doesn't click it anyway :(
        ExitLoop
    EndIf
 Next

 

Many thanks, ProgrammerKid. I totally agree about the underlying code being terrible. I think it's auto-generated by the statistical software package SAS.

I'll have a think about the MouseClick command. Really appreciate your thoughts, thanks.

Link to comment
Share on other sites

20 minutes ago, Danp2 said:

You should be able to just parse the HTML to get the required values and then use InetGet to download the file. For example:

The URL for one of the files is https://rptsvr1.tea.texas.gov/cgi/sas/broker?_service=marykay&_program=perfrept.perfmast.sas&prgopt=2005%2Fayp%2Fpdfcx.sas&year4=2005&year2=05&topic=ayp&gifname=t_05aypcamp&title=AYP%2BReport&level=Campus&search=campback&sublevel=SUBLEVEL&ptype=PTYPE&campback=108902001+

Instead of traversing the website with the IE functions, just use the desired campback value in the URL and download the file.

 

Wow! I can't believe I didn't closely examine the URL - this definitely appears to be a better approach. Thanks very much, Danp2!

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