Ask Your Question
0

How to navigate data from webpage in libre-macro?

asked 2017-08-08 09:40:04 +0100

Muthulakshmi gravatar image

updated 2017-08-08 11:26:21 +0100

JohnSUN gravatar image

.

**Navigate data from web page coding in libre macro as follows:**
        Sub navigateurl()
        URL = "http://keystonemanagement.com/apartments/me"

        Set IE = CreateObject("InternetExplorer.Application")
        IE.Visible = True
        IE.Navigate URL

        Do While IE.ReadyState <> 4
           DoEvents
         Loop

        Set propertyname = IE.document.getElementsByTagName("h4")
        number = propertyname.Length
        For i = 0 To number - 1

          ThisComponent.Sheets(0).getCellbyPosition(i, 0) = propertyname(i).innerText
          ThisComponent.Sheets(0).getCellbyPosition(i,0) = propertyname(i).getElementsByTagName("a")(0).href

        Next i
        End Sub

When I run this coding, came error as "BASIC runtime error.Object variable not set." How to execute this coding?

edit retag flag offensive close merge delete

Comments

Can you please (a) enclose all your code in your question in Code tags: and (b) tell us on which line the error occurs.

robleyd gravatar imagerobleyd ( 2017-08-08 10:59:42 +0100 )edit

2 Answers

Sort by » oldest newest most voted
0

answered 2017-08-08 11:13:45 +0100

Muthulakshmi gravatar image

Codings: Sub navigateurl() Dim number As Integer Dim URL As String Dim propertyname As Object

URL = "http://keystonemanagement.com/apartme..."

Set IE = CreateObject("InternetExplorer.Application") IE.Visible = True IE.Navigate URL

Do While IE.ReadyState <> 4 Doevents Loop

Set propertyname = IE.document.getElementsByTagName("h4") number = propertyname.Length For i = 0 To number - 1

ThisComponent.Sheets(0).getCellbyPosition(i, 0) = propertyname(i).innerText ThisComponent.Sheets(0).getCellbyPosition(i,0) = propertyname(i).getElementsByTagName("a")(0).href

Next i

End Sub

The error came in this step "Set propertyname = IE.document.getElementsByTagName("h4")"

edit flag offensive delete link more
0

answered 2017-08-08 15:33:00 +0100

JohnSUN gravatar image

updated 2017-08-09 16:46:22 +0100

Please try this variant macro

Option VBASupport 1

Sub navigateurl()
    URL = "http://keystonemanagement.com/apartments/me"

    Set ie = CreateObject("InternetExplorer.Application")
    ie.Visible = True
    ie.Navigate URL

    Do While ie.ReadyState <> 4
        DoEvents
    Loop

    oSheet = ThisComponent.getSheets().getByIndex(0)

    doc = ie.document.body
    Elements = doc.getElementsByTagName("h4")
    I = 1
    For Each element In Elements
        For Each el In element.all
            oSheet.getCellByPosition(0, I).setString(element.innerText)
            oSheet.getCellByPosition(1, I).setString(el.href)
            I = I + 1
        Next el
    Next element
    ie.Quit
    Set ie = Nothing
End Sub

Try run this macro from this demo file

Update This version used only office tools, without IE - collectDataFromURL.ods

edit flag offensive delete link more

Comments

Hi, here coding as "For Each element In Elements" step error came as "Inadmissible value or data type. Data type mismatch." and also coding as "oSheet.getCellByPosition(0, I).setString(element.innerText)" error as "BASIC runtime error. Property or method not found: innerText"

How to overcome this issues??

Muthulakshmi gravatar imageMuthulakshmi ( 2017-08-09 07:08:53 +0100 )edit

What version of the office and which operating system are you using? Perhaps this affects the result ... Do you want to collect data from the page only? Perhaps there is an easier way (without using the Internet Explorer). I added the file to my answer - it works well for me. Try it.

JohnSUN gravatar imageJohnSUN ( 2017-08-09 07:57:33 +0100 )edit

Now I have used LibreOffice version Version: 5.4.0.3. I want to collect data from web page only.

Muthulakshmi gravatar imageMuthulakshmi ( 2017-08-09 09:42:29 +0100 )edit

Windows 10?

JohnSUN gravatar imageJohnSUN ( 2017-08-09 10:47:37 +0100 )edit

My system is Windows 8

Muthulakshmi gravatar imageMuthulakshmi ( 2017-08-09 11:19:04 +0100 )edit

May you send coding for libre calc macro web page extracting without using Internet Explorer?

Muthulakshmi gravatar imageMuthulakshmi ( 2017-08-09 12:17:53 +0100 )edit

Right now I debug this version of macro (open URL as calc_HTML_WebQuery, enumerate non-empty cells, extract hyperlinks from each of them, filter links to appartaments - there are many other links - and create result table) - please be patient

JohnSUN gravatar imageJohnSUN ( 2017-08-09 12:52:28 +0100 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-08-08 09:40:04 +0100

Seen: 556 times

Last updated: Aug 09 '17