Web Page Scrape

Forum to discuss MLScript plugin that enables VBScript and JavaScript scripting within MLServer3.
User avatar
jjjukebox
Is there life beyond Cinemar?
Is there life beyond Cinemar?
Posts: 1024
Joined: Sat May 22, 2004 9:54 pm
Location: Toronto
Contact:

Web Page Scrape

Postby jjjukebox » Thu Mar 26, 2009 10:06 am

Is there a command or means in MLScript to bring a web page into a variable?

I currently use HomeSeer to do this with the following HomeSeer command:

strUnstripped_Page = hs.GetURL(WEBSITE_HOSTNAME, WEBSITE_END_URL, STRIP_TAGS, WEB_PORT)

Only use HomeSeer now for multiple scripts to bring infointo ML and would love to replace it wirth MLScript.

Mant Thanx
J.J. Jukebox
Member

User avatar
CinemarDave
Site Admin
Site Admin
Posts: 10535
Joined: Fri Feb 07, 2003 8:56 am
Location: Planet Earth
Contact:

Postby CinemarDave » Thu Apr 02, 2009 5:11 pm

Very easy

Code: Select all

Option Explicit

   Dim url
   Dim xmlhttp
   Dim Response

   url = "http://www.cinemaronline.com"
   Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
   xmlhttp.open "GET", url, 0
   xmlhttp.send ""

   Response = xmlhttp.responseText

   msgbox Response

   Set xmlhttp = Nothing


User avatar
jjjukebox
Is there life beyond Cinemar?
Is there life beyond Cinemar?
Posts: 1024
Joined: Sat May 22, 2004 9:54 pm
Location: Toronto
Contact:

Re: Web Page Scrape

Postby jjjukebox » Sun Dec 19, 2010 10:27 pm

Dave,

I am making a variable importer from an xml file and would like tp know how I could modify the above to read (GET) the contents from an XML file from a local network address like \\192.168.2.10\MLServer\CommandVariablesExport.xml or \\Server\MLServer\CommandVariablesExport.xml.

Thanx
J.J. Jukebox

Member

User avatar
jjjukebox
Is there life beyond Cinemar?
Is there life beyond Cinemar?
Posts: 1024
Joined: Sat May 22, 2004 9:54 pm
Location: Toronto
Contact:

Re: Web Page Scrape

Postby jjjukebox » Mon Dec 20, 2010 1:59 am

It is a little crude but what I came up with is:

Code: Select all

Dim NodeNums, HomeTekServer

Const VARIABLENAME_START_POSITION =      "<name>"
Const VARIABLENAME_END_POSITION =      "</name>"
Const VARIABLEVALUE_START_POSITION =      "<value>"
Const VARIABLEVALUE_END_POSITION =      "</value>"

HomeTekServer = MLServer.GetVariable ("HomeTekServer")

Set xmlDoc = CreateObject("Msxml2.DOMDocument")
xmlDoc.load("\\" & HomeTekServer & "\MLServer\CommandVariablesExport.xml")
strVariablePage = xmlDoc.xml

Set NodeNums = xmlDoc.documentElement


iVariableNameEnd = "1"

'===================== Get & Write Variable Names & Values============================

For Num = 1 to NodeNums.childNodes.length

iVariableNameStart = (Instr (iVariableNameEnd, strVariablePage, VARIABLENAME_START_POSITION)) + LEN(VARIABLENAME_START_POSITION)
iVariableNameEnd = Instr (iVariableNameStart, strVariablePage, VARIABLENAME_END_POSITION)
strVariableName = Mid(strVariablePage, iVariableNameStart, iVariableNameEnd - iVariableNameStart)

iVariableValueStart = (Instr (iVariableNameEnd, strVariablePage, VARIABLEValue_START_POSITION)) + LEN(VARIABLEVALUE_START_POSITION)
iVariableValueEnd = Instr (iVariableValueStart, strVariablePage, VARIABLEVALUE_END_POSITION)
strVariableValue = Mid(strVariablePage, iVariableValueStart, iVariableValueEnd - iVariableValueStart)

MLServer.SetVariable strVariableName,  strVariableValue

Next


MsgBox "Imported " & NodeNums.childNodes.length & " Variables"


An example of the xml file is:

Code: Select all

  <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
- <dataroot>
- <TblVariables>
  <name>designeraugustgallerybutton1tint</name>
  <value>30</value>
  </TblVariables>
- <TblVariables>
  <name>designeraugustgallerybutton2alpha</name>
  <value>100</value>
  </TblVariables>
- <TblVariables>
  <name>designeraugustgallerybutton2colour</name>
  <value>0x6699FF</value>
  </TblVariables>
- <TblVariables>
  <name>designeraugustgallerybutton2tint</name>
  <value>30</value>
  </TblVariables>
  </dataroot>


I know there are xmlDoc functions for picking out the name and values automatically but I am not sure how yet.

Anyone suggest a better way to this VBscript cripple?

Later
J.J. Jukebox

Member

User avatar
CinemarDave
Site Admin
Site Admin
Posts: 10535
Joined: Fri Feb 07, 2003 8:56 am
Location: Planet Earth
Contact:

Re: Web Page Scrape

Postby CinemarDave » Mon Dec 20, 2010 11:38 am

something like this should get you pretty close

Code: Select all

Option Explicit

Dim HomeTekServer, xmlDoc, Node, Name, Value

HomeTekServer = MLServer.GetVariable("HomeTekServer")
Set xmlDoc = CreateObject("Msxml2.DOMDocument")
xmlDoc.load("\\" & HomeTekServer & "\MLServer\CommandVariablesExport.xml")

For Each Node in xmldoc.getElementsByTagName("TblVariables")
   Name = node.childNodes(0).text
   Value = node.childNodes(1).text
   MLServer.SetVariable cStr(Name), cStr(Value)
next

User avatar
jjjukebox
Is there life beyond Cinemar?
Is there life beyond Cinemar?
Posts: 1024
Joined: Sat May 22, 2004 9:54 pm
Location: Toronto
Contact:

Re: Web Page Scrape

Postby jjjukebox » Mon Dec 20, 2010 11:50 am

Brilliant!! =D>

Guess I am going to have to take the time to broaden my scripting level.

I am going to attempt to bring all my HomeSeer scripts into ML

Many Thanx
J.J. Jukebox

Member


Return to “MLScript”

Who is online

Users browsing this forum: No registered users and 1 guest