Get content from html page

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
vedus
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 153
Joined: Tue Feb 26, 2013 9:23 am

Get content from html page

Post by vedus » Tue Sep 02, 2014 1:46 pm

i am using the bellow code to show the html page on the mobiles..
It is possible to get the html return data and stored on var for future processing ?

Code: Select all

Global browserID
Global theURL
Global thehtmlFile

on preopencard
     -- Create our browser control and store the id
     if the platform is "android" then
          mobileControlCreate "browser"
    put the result into BrowserID
    mobileControlSet browserID, "rect", the rect of group "tbrowser"
    mobileControlSet browserID, "visible", "true"
    mobileControlSet BrowserID, "url", theURL
  else
       iphoneControlCreate "browser"
       put the result into BrowserID
       -- Native controls start off invisible
       iphoneControlSet BrowserID, "rect", the rect of group "tbrowser"
    iphoneControlSet browserID, "visible", "true"
       -- Set up a suitable initial url
       iphoneControlSet BrowserID, "url", theURL
     end if
  
end preOpenCard

on closeCard
   if the environment is not "mobile" then
        exit closeCard
   end if
   -- Destroy the control, if we fail to do this native UIViews
   -- will just accumulate
   if the platform is "android" then
        mobileControlDelete BrowserID
  delete URL("file:" & thehtmlFile) 
      else
           iphoneControlDelete BrowserID
  delete file thehtmlFile
         end if
end closeCard

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Get content from html page

Post by Klaus » Tue Sep 02, 2014 2:06 pm

Hi vedus,

hm, no word about this in the dictionary!?
But you can always:
...
put url theURL into aVariable
...
and store that somewhere in the users documents folder. :D


Best

Klaus

vedus
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 153
Joined: Tue Feb 26, 2013 9:23 am

Re: Get content from html page

Post by vedus » Tue Sep 02, 2014 2:20 pm

Klaus wrote:Hi vedus,

hm, no word about this in the dictionary!?
But you can always:
...
put url theURL into aVariable
...
and store that somewhere in the users documents folder. :D


Best

Klaus
hi klaus,
exist in the dictionary but trying to figure out why i get nothing from this command.
i am using the simulator for the iphone and i don't get the results from the put command
i get empty text fld.
here is the complete code from card 1

Code: Select all

global myarray
Global browserID
Global theURL
global tTitles
global thehtmlFile

on opencard
  dbArrayToCard myarray
      # quit if we are not on a mobile device
      if the environment is not "mobile" then exit opencard
  
    #Store Location 
  put fld"lat"& comma & fld"long" into Store_lng
  if fld"lat"or fld"long" is empty then
    //if store_lng is empty then
    answer error "No Gps Data"
    Answer "NOT able to track GPS location"
  end if
    
  #current location
  wait 2000 millisecs
  put mobileCurrentLocation() into tLocation
  put tLocation["latitude"] into fld "Dlat" 
  put tLocation["longitude"] into fld "Dlong" 
  put fld"Dlat"& comma & fld"Dlong" into lat_lng
 

  if lat_lng is empty then
    answer error "NOT able to track GPS location"
  end if
  

  put specialFolderPath("documents") & "/navi2.html" into documentFilePath
       if there is not a file documentFilePath then
              put specialFolderPath("engine") & "/navi2.html" into engineFilePath
              put URL ("binfile:" & engineFilePath) into URL ("binfile:" & documentFilePath)
       end if
  put empty into theData
  put specialFolderPath("documents") & "/navi2.html" into thehtmlFile
          put URL("file:" & thehtmlFile) into theData
          
  put "var origin1 = new google.maps.LatLng(" & lat_lng & ");" into line 30 of theData
  put "var destinationA = new google.maps.LatLng(" & Store_lng & ");" into line 31 of theData
  put "zoom:17," into line 37 of theData
  
  put theData into URL ("file:" & thehtmlFile)
    put "file://" & specialFolderPath("documents") & "/navi2.html" into theURL
          replace space with "%20" in theURL

end OpenCard
and here the card 2 with the map results

Code: Select all

Global browserID
Global theURL
Global thehtmlFile

on preopencard
     -- Create our browser control and store the id
     if the platform is "android" then
          mobileControlCreate "browser"
    put the result into BrowserID
    mobileControlSet browserID, "rect", the rect of group "tbrowser"
    mobileControlSet browserID, "visible", "true"
    mobileControlSet BrowserID, "url", theURL
  else
       iphoneControlCreate "browser"
       put the result into BrowserID
       -- Native controls start off invisible
       iphoneControlSet BrowserID, "rect", the rect of group "tbrowser"
    iphoneControlSet browserID, "visible", "true"
       -- Set up a suitable initial url
       iphoneControlSet BrowserID, "url", theURL
     end if
  
end preOpenCard

on opencard
  put url theURL into tMap
  answer tMap
put tMap int fld mapR
end opencard



on closeCard
   if the environment is not "mobile" then
        exit closeCard
    put empty into fld "lat"  of card drecords
  put empty into fld "long" of card drecords
   end if
   -- Destroy the control, if we fail to do this native UIViews
   -- will just accumulate
   if the platform is "android" then
        mobileControlDelete BrowserID
  delete URL("file:" & thehtmlFile) 
      else
           iphoneControlDelete BrowserID
  delete file thehtmlFile
         end if
end closeCard

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Get content from html page

Post by Klaus » Tue Sep 02, 2014 3:10 pm

Hi vedus,

you can check the result, maybe that will give you some hints.

Code: Select all

on opencard
  put url theURL into tMap
  answer the result
  ## Should be empty on success
...
Best

Klaus

vedus
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 153
Joined: Tue Feb 26, 2013 9:23 am

Re: Get content from html page

Post by vedus » Tue Sep 02, 2014 3:17 pm

Klaus wrote:Hi vedus,

you can check the result, maybe that will give you some hints.

Code: Select all

on opencard
  put url theURL into tMap
  answer the result
  ## Should be empty on success
...
Best

Klaus
i have try it.
the first result from popUp windows is tMap
and after i press the ok i get "can't open file"
i know the file is local but exist on the documents folder,and the results is coming from google maps server... :(
here is the photo from the results https://www.dropbox.com/s/nh5w8l7z09y63 ... 6.png?dl=0
Last edited by vedus on Tue Sep 02, 2014 3:24 pm, edited 1 time in total.

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Get content from html page

Post by Klaus » Tue Sep 02, 2014 3:22 pm

Sorry, mixed your variable names!

Of course I do not mean your HTML file on disk, but the real URL that you want to fetch and store -> http://...
Maybe -> theData?

vedus
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 153
Joined: Tue Feb 26, 2013 9:23 am

Re: Get content from html page

Post by vedus » Tue Sep 02, 2014 4:37 pm

Klaus wrote:Sorry, mixed your variable names!

Of course I do not mean your HTML file on disk, but the real URL that you want to fetch and store -> http://...
Maybe -> theData?
unfortunately with ->theData i get the local content.. :(
still try to figure out ....

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Get content from html page

Post by Klaus » Tue Sep 02, 2014 5:05 pm

Sorry, no idea what HTML you mean in the end? 8)

Hint:
No need to differ between iOS and ANDROID!
The commands for "mobilecontrol..." etc. are identical since version 6.xxx
...
## if the platform is "android" then
## These commands are valid for BOTH Android AND iOS:
mobileControlCreate "browser"
put the result into BrowserID
mobileControlSet browserID, "rect", the rect of group "tbrowser"
mobileControlSet browserID, "visible", "true"
mobileControlSet BrowserID, "url", theURL
...

Post Reply