LogicMachine Forum
Logic Machine Communication - HTTP - Printable Version

+- LogicMachine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Logic Machine Communication - HTTP (/showthread.php?tid=712)



Logic Machine Communication - HTTP - Rodriguez - 31.03.2017

Hello, I would like to know, how can I take information from an HTTP page from the logic machine? Big Grin


RE: Logic Machine Communication - HTTP - admin - 31.03.2017

http://w3.impa.br/~diego/software/luasocket/http.html#request


RE: Logic Machine Communication - HTTP - Erwin van der Zwart - 31.03.2017

Hi,

If you just need a simple datafield you can also use:

Code:
require('socket.http') socket.http.TIMEOUT = 5 -- Get data from website local data = socket.http.request('http://openrb.com') -- Check if data is received if not data then     log('No data found')     return end -- Find your data for i in string.gmatch(data, '<body>.-</body>') do     if i ~= nil then         searched_data = i:match([[<h2>(.-)</h2>]])         if i ~= nil then             log(searched_data)         end     end end
BR,

Erwin


RE: Logic Machine Communication - HTTP - Rodriguez - 31.03.2017

Hi, Erwin van der Zwar:
Thanks for your help. Yes, it is a simple data capture, use your code but it is not registering anything to me.


RE: Logic Machine Communication - HTTP - Erwin van der Zwart - 31.03.2017

Hi,

The data is now fetched between <h2> </h2> fields but i don't know the fields in your html mark-up so you have to check that and change it to those..

log(data) to see your complete reply from your url source.. or right click your source in the browser and select 'view source code' to see the structure of the site you read..

BR,

Erwin


RE: Logic Machine Communication - HTTP - admin - 01.04.2017

Check is gateway and DNS are set in network config.


RE: Logic Machine Communication - HTTP - Erwin van der Zwart - 01.04.2017

Hi,

I adjusted the sample to a (tested) version to fetch all the main topics from this forum

Code:
require('socket.http') socket.http.TIMEOUT = 5 -- Get data from website local data = socket.http.request('http://forum.logicmachine.net') -- Check if data is received if not data then   log('No data found')   return end -- Find your data for i in string.gmatch(data, '<body>.-</body>') do   if i ~= nil then      for j in string.gmatch(i, '<a href="forumdisplay.-</a>') do         if j ~= nil then            searched_data = j:match([[">(.-)</a>]])            if searched_data ~= nil then               log(searched_data)            end         end      end   end end

BR,

Erwin


RE: Logic Machine Communication - HTTP - Rodriguez - 04.04.2017

It works, thanks for your help. Big Grin