Reading HTML Code From a Website in LabVIEW

Updated Oct 26, 2023

Environment

Software

  • LabVIEW

I would like to use LabVIEW to read raw HTML data from a website. What functions are available in LabVIEW to accomplish this?

You can read raw HTML data from a website using the HTTP VIs within LabVIEW. These VIs are located in the functions palette under Data Communication»Protocols»HTTP Client.


Follow the steps below to read the entire HTML source code from a specific website.
  1. Right-click on the block diagram, and select Data Communications»Protocols»HTTP Client»GET.
  2. Create an empty string constant or control by right-clicking on the url terminal of GET.vi and selecting Create»Constant or Create»Control. Insert the URL for the website you that contains the HTML you are trying to retrieve.
  3. Create an indicator for the GET.vi's body output.


For more complex requests, authentication, or a connection preserved over multiple requests, use a client handle.

To create this piece of code:
  1. Right-click on the block diagram, and select Data Communications»Protocols»HTTP Client»Open Handle
  2. Select the GET function on the functions palette by navigating to Data Communications»Protocols»HTTP Client»GET. Wire the client handle out from the Open Handle VI to the client handle terminal on GET.vi. Next, create an empty string constant or control by right-clicking on the url terminal and selecting Create»Constant or Create»Control. Insert the URL for the website you that contains the HTML code you are trying to retrieve.
  3. Create an indicator for GET.vi's body output.
  4. Place the Close Handle function on the block diagram by selecting Data Communications»Protocols»HTTP Client»Close Handle from the functions palette. Wire the client handle out from the GET VI to the client handle on the Close Handle VI. In addition, connect the error clusters between the three HTTP VIs.
  5. After executing, the body indicator should contain the HTML data from the website.

Additional Information

If you need to add or change headers to the HTTP request you are sending, you can use the Add Header VI located at Data Communications»Protocols»HTTP Client»Headers»Add Header.

GET.vi does not follow redirects. Use its headers output to analyze the headers the web server returned.

You can use the functions on the String palette to parse HTML code and extract useful data. Functions that is useful for doing this are String»Match Pattern and String»Match Regular Expression.