Jump to content

To fetch the data of a particular div inside the website


Jess
 Share

Recommended Posts

Hi,

I am writing a script where in I have to go to particular tab inside a website and write all the data in that div to word and also show it in a msgbox.

I have written a code but it showing errors.Please review the script.

 

Thanks

$divs = _IETagNameGetCollection($oIE, "div")

For $div In $divs
    If $div.className == "yui3-tab-panel yui3-tab-panel-selected" Then
        MsgBox(0, "text", $div.innerText)
    EndIf
Next

 

Link to comment
Share on other sites

Hi @Jess,

Quote

and write all the data in that div to word

Do you mean that you want to copy the content of a portion of a specific website which contains this specific div classname to Microsoft Word?

It would help if you could provide the website's url also ;)

Edited by Neutro
Link to comment
Share on other sites

I'll try :)

Can you provide the url of the website that you're trying to retreive data from, or a substitute that can be used as an example?

Edited by Neutro
Link to comment
Share on other sites

There is no div with the classname "

yui3-tab-panel yui3-tab-panel-selected

in the url that you provided, but i guess you are refering to a page you get after you login to that website.

#include <IE.au3>
#include <MsgBoxConstants.au3>

Local $oIE = _IECreate("https://developer.mozilla.org/fr/docs/Web/API/Node/textContent", 1)

$divs = _IETagNameGetCollection($oIE, "div")

For $div In $divs
    If $div.className = "wrap center" Then
        MsgBox(0, "text", $div.innertext)
    EndIf
Next

_IEQuit($oIE)

Your solution is working if the classname "yui3-tab..." exists for a specific div element and contains text in the webpage you are looking for.

If you have errors with it, it might be because the classname does not exists in the url/webpage you are searching into.

Link to comment
Share on other sites

Hi,

This is the error I am getting

IE.au3 T3.0-2 Error from function _IELoadWait, $_IESTATUS_InvalidObjectType ()
 IE.au3 T3.0-2 Error from function _IEGetObById, $_IESTATUS_InvalidObjectType

 

thanks

Link to comment
Share on other sites

url : https://cmooc.cognizant.com/course/view.php?id=33

That class name is there in this url. Please see to it.

Here is the code

#include <GuiTab.au3>
#include<String.au3>
#include <AutoItConstants.au3>
#include <IE.au3>
#include <Array.au3>



; Run Google Chrome
 Run("C:\Program Files\Google\Chrome\Application\chrome.exe")

;$oIE = _IECreate("https://cmooc.cognizant.com/")

WinWaitActive("[Intermediate D3D Window]","",10)


; Open a new tab with Ctrl+t
Sleep(9000)

Send("https://cmooc.cognizant.com/{ENTER}")
; Type the address and press Enter in one command
Sleep(5000)

Send('{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{ENTER}')
sleep(7000)

MouseClick( $MOUSE_CLICK_PRIMARY,528,623)

Local $oDiv = _IEGetObjById($oIE, "section-1")
;$divs = _IETagNameGetCollection($oIE, "div")

For $div In $divs
    If $div.className == "yui3-tab-panel yui3-tab-panel-selected" Then
        MsgBox(0, "text", $div.innerText)
    EndIf
Next

 

Link to comment
Share on other sites

Only you can access this url because you're already logged to this website :)

If you logout and try to connect to it again, it goes back to  https://cmooc.cognizant.com

But please DO NOT SEND YOUR LOGIN / PASSWORD to anyone, including me :D 

So basicly you are trying to retrieve data from a website of a company from which you are a customer from? Most of the time companies like cognizant for you have APIs they develop to do precisely what you are trying to do. 

Instead of having troubles doing this manually, you should try to contact their support first, explain them what you are trying to achieve and ask them if they have an API that you could use to do it :)

Edited by Neutro
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...