Get webpage content form URL

This groovy example will show how to get fetch the contents of a web page. A similar example shows how get content from a url or uri in java.

public void get_url_content() {

    def urlContents = "".toURL().getText()

    urlContents.eachLine {
        println it //read each line of the web page99


<!DOCTYPE html>
<html lang="en" class="">
<head prefix="og: fb: object: article: profile:">
<meta charset='utf-8'>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="Content-Language" content="en">

<title>levelup-java-examples/ at master · leveluplunch/levelup-java-examples · GitHub</title>
<link rel="search" type="application/opensearchdescription+xml" href="/opensearch.xml" title="GitHub">


    <div id="ajax-error-message" class="flash flash-error">
  <span class="octicon octicon-alert"></span>
  <a href="#" class="octicon octicon-x flash-close js-ajax-error-dismiss" aria-label="Dismiss error"></a>
  Something went wrong with that request. Please try again.

  <script crossorigin="anonymous" src="" type="text/javascript"></script>
  <script async="async" crossorigin="anonymous" src="" type="text/javascript"></script>