Error getting web page data into Libre Office Calc

Viewed 9

I have a macro in Libre Office that has worked for over a year now. I did a fresh install of Libre Office, and it no longer works. The spreadsheet was unchanged from before the install

Public Function GetValue (sURL as String)
' Returns the value scraped from website provided in sURL in string format
'
  dim oSimpleFileAccess as Object   
  dim oInpDataStream as Object      
  dim sContent as string            ' HTML content of webpage
  dim sNewContent as string         ' Modified HTML 
  dim lStartPos as long             ' Location of To Find String
  dim delimiters() as Long          ' String delimiters array (Needed for readString)
  dim i as long                     ' Loop counter

  msgbox sURL

  'Open URL and put HTML into sContent variable    
  oSimpleFileAccess = createUNOService ("com.sun.star.ucb.SimpleFileAccess")
  oInpDataStream = createUNOService ("com.sun.star.io.TextInputStream")
  
  ' Goes to error if unable to open website
  on error Goto BadURL
  msgbox "In Error"
  oInpDataStream.setInputStream(oSimpleFileAccess.openFileRead(sUrl))
  msgbox "Out Error"
  on error goto 0
...

I am getting Err:502 in the cell when used. Using the msgboxes above, I have narrowed the problem down to the the following line:

oInpDataStream.setInputStream(oSimpleFileAccess.openFileRead(sUrl))

The first msgbox "In Error" is shown, however the second is never shown. Do I need to add a reference in LibreOffice as needs to be done in Excel VBA? I could find no documentation for this.

Also, I am curious as to why the On Error does not appear to be working. My Error goto looks like this:

  BadURL:
  GetValue = "ERR: Bad Address"

It should return an error of 'ERR: Bad Address' but it is returning 'ERR:502' instead, like it is ignoring the 'On Error' statement.

For clarification, I derived this web page scrape from the information found here:

https://stackoverflow.com/questions/25330550/reading-html-page-using-libreoffice-basic

As noted in a comment in this forum, this may not be the best way best way to parse a web page. Is there a better way to do this?

0 Answers
Related