Jump to content
oemript

How to export content into Text files?

Recommended Posts

oemript

Referring to following link, I would like to know on how to perform following task using AutoIT as shown below:

1) Click Next

2) Export html content into D:\Page1.txt

3) Click Next

4) Export html content into D:\Page2.txt

5) Click Next

6) Export html content until the end of last page.

Does anyone have any suggestions?
Thanks in advance for any suggestions

https://www.cmu.org.hk/cmupbb_ws/eng/page/wmp0100/wmp010001.aspx

 

Share this post


Link to post
Share on other sites
FrancescoDiMuro
Posted (edited)

@oemript

What did you try so far?

Post the code you are working on, and we would be happy to help you :)

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

ALWAYS GOOD TO READ:

Share this post


Link to post
Share on other sites
gruntydatsun

Have a look at the IE library in the helpfile.  It will make those operations pretty easy.

Share this post


Link to post
Share on other sites
oemript
Posted (edited)

I don't know on how to locate the Next and click on it, and the rest of process is OK to be handled without any problem.

Do you have any suggestions?
Thanks, to everyone very much for any suggestions (^v^)

 

Edited by oemript

Share this post


Link to post
Share on other sites
Subz
#include <IE.au3>
While ProcessExists("iexplore.exe")
    ProcessClose("iexplore.exe")
WEnd
Global $sHTMLSavePath = @ScriptDir & "\IEData"  ;~ Folder Path to Save HTML Documents
Global $oIE = _IECreate("https://www.cmu.org.hk/cmupbb_ws/eng/page/wmp0100/wmp010001.aspx")
Sleep(5000)     ;~ Wait while page loads
Global $i = 1   ;~ Page Number
_GetSiteData($oIE, "Next")

Func _GetSiteData($p_oIEObject, $p_sLinkText)
    Local $oAnchors, $sLinkText, $hFileOpen, $bLinkText = False
    Local $oTableCells = _IETagNameGetCollection($oIE, "td")    ;~ Search for TD containing Navigation Bar Urls i.e. < Previous | Page 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 | Next >
    For $oTableCell In $oTableCells
        If $oTableCell.className = "blue01_12px" Then   ;~ TD ClassName matches known Navigational Bar ClassName
            $oAnchors = _IETagNameGetCollection($oTableCell, "a")
            For $oAnchor In $oAnchors   ;~ Check the InnerText matches 2nd Parameter of _GetSiteData() function
                $sLinkText = _IEPropertyGet($oAnchor, "innerText")
                    If @error Then ContinueLoop ;~ InnerText not found Continue Looping
                If $sLinkText = $p_sLinkText Then   ;~ InnerText matches  2nd Parameter of _GetSiteData() function
                    $bLinkText = True   ;~ Notification a Link was found
                    _IELinkClickByText($oAnchor, $p_sLinkText)  ;~ Click the Link
                    Sleep(3000) ;~ Wait 3 Seconds while page loads
                    $sBodyHTML = _IEBodyReadHTML($oIE)  ;~ Read HTML Body
                    $hFileOpen = FileOpen($sHTMLSavePath & "\Page#" & $i & ".html", 10) ;~ Create new document ...\IEData\Page#x.html
                        FileWrite($hFileOpen, $sBodyHTML)   ;~ Write HTML Body to ...\IEData\Page#x.html
                    FileClose($hFileOpen)   ;~ Close FileOpen
                    $i += 1
                    ExitLoop 2
                EndIf
            Next
        EndIf
    Next
    If $bLinkText = False Then Exit ;~ Notification no further page numbers were found, exit script.
    _GetSiteData($oIE, $i)
EndFunc

 

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
oemript

Thanks, to everyone very much for suggestions (^v^)

Share this post


Link to post
Share on other sites
oemript
3 hours ago, Subz said:
#include <IE.au3>
While ProcessExists("iexplore.exe")
    ProcessClose("iexplore.exe")
WEnd
Global $sHTMLSavePath = @ScriptDir & "\IEData"  ;~ Folder Path to Save HTML Documents
Global $oIE = _IECreate("https://www.cmu.org.hk/cmupbb_ws/eng/page/wmp0100/wmp010001.aspx")
Sleep(5000)     ;~ Wait while page loads
Global $i = 1   ;~ Page Number
_GetSiteData($oIE, "Next")

Func _GetSiteData($p_oIEObject, $p_sLinkText)
    Local $oAnchors, $sLinkText, $hFileOpen, $bLinkText = False
    Local $oTableCells = _IETagNameGetCollection($oIE, "td")    ;~ Search for TD containing Navigation Bar Urls i.e. < Previous | Page 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 | Next >
    For $oTableCell In $oTableCells
        If $oTableCell.className = "blue01_12px" Then   ;~ TD ClassName matches known Navigational Bar ClassName
            $oAnchors = _IETagNameGetCollection($oTableCell, "a")
            For $oAnchor In $oAnchors   ;~ Check the InnerText matches 2nd Parameter of _GetSiteData() function
                $sLinkText = _IEPropertyGet($oAnchor, "innerText")
                    If @error Then ContinueLoop ;~ InnerText not found Continue Looping
                If $sLinkText = $p_sLinkText Then   ;~ InnerText matches  2nd Parameter of _GetSiteData() function
                    $bLinkText = True   ;~ Notification a Link was found
                    _IELinkClickByText($oAnchor, $p_sLinkText)  ;~ Click the Link
                    Sleep(3000) ;~ Wait 3 Seconds while page loads
                    $sBodyHTML = _IEBodyReadHTML($oIE)  ;~ Read HTML Body
                    $hFileOpen = FileOpen($sHTMLSavePath & "\Page#" & $i & ".html", 10) ;~ Create new document ...\IEData\Page#x.html
                        FileWrite($hFileOpen, $sBodyHTML)   ;~ Write HTML Body to ...\IEData\Page#x.html
                    FileClose($hFileOpen)   ;~ Close FileOpen
                    $i += 1
                    ExitLoop 2
                EndIf
            Next
        EndIf
    Next
    If $bLinkText = False Then Exit ;~ Notification no further page numbers were found, exit script.
    _GetSiteData($oIE, $i)
EndFunc

Thanks, to everyone very much for suggestions (^v^)

 

Share this post


Link to post
Share on other sites
Earthshine

suggestion? you just want the code. admit it.

  • Haha 1

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
JLogan3o13

As has been stated before, if you're not happy with a poster's level of effort - don't help them. Don't pollute the thread with unnecessary commentary as it inevitably leads to arguing back and forth.

  • Like 1

√-1 2^3 ∑ π, and it was delicious!

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

×