Module that provides Web functions (e.g url_encode
, json
, wget
...)
In order to use the functions provided by this module, you need to import this module:
>>> import Web
html_decode(text)
Decodes a HTML input string (replacing &
by &
)
text
: The input stringThe input string removed with any HTML entities.
>>> "<p>This is a paragraph</p>" |> html_encode
# "<p>This is a paragraph</p>" |> html_encode
out = "<p>This is a paragraph</p>"
>>> out |> html_decode
# out |> html_decode
out = "<p>This is a paragraph</p>"
html_encode(text)
Encodes a HTML input string (replacing &
by &
)
text
: The input stringThe input string with HTML entities.
>>> "<p>This is a paragraph</p>" |> html_encode
# "<p>This is a paragraph</p>" |> html_encode
out = "<p>This is a paragraph</p>"
>>> out |> html_decode
# out |> html_decode
out = "<p>This is a paragraph</p>"
html_strip(text)
Removes any HTML tags from the input string
text
: The input stringThe input string removed with any HTML tags
>>> "<p>This is a paragraph</p>" |> html_strip
# "<p>This is a paragraph</p>" |> html_strip
out = "This is a paragraph"
json(value)
Converts to or from a JSON object depending on the value argument.
value
: A value argument:
A JSON string or an object/array depending on the argument.
>>> json {a: 1, b: 2, c: [4,5], d: "Hello World"}
# json({a: 1, b: 2, c: [4,5], d: "Hello World"})
out = "{\"a\": 1, \"b\": 2, \"c\": [4, 5], \"d\": \"Hello World\"}"
>>> json out
# json(out)
out = {a: 1, b: 2, c: [4, 5], d: "Hello World"}
url_decode(url)
Converts a URL-encoded string into a decoded string.
url
: The URL to decode.The decoded URL
>>> url_decode "this%3Cis%3Ean%3Aurl+and+another+part"
# url_decode("this%3Cis%3Ean%3Aurl+and+another+part")
out = "this<is>an:url and another part"
url_encode(url)
Converts a specified URL text into a URL-encoded.
URL encoding converts characters that are not allowed in a URL into character-entity equivalents. For example, when the characters < and > are embedded in a block of text to be transmitted in a URL, they are encoded as %3c and %3e.
url
: The url text to encode as an URL.An encoded URL.
>>> url_encode "this<is>an:url and another part"
# url_encode("this<is>an:url and another part")
out = "this%3Cis%3Ean%3Aurl+and+another+part"
url_escape(url)
Identifies all characters in a string that are not allowed in URLS, and replaces the characters with their escaped variants.
url
: The input string.The input string url escaped
>>> "<hello> & <scriban>" |> url_escape
# "<hello> & <scriban>" |> url_escape
out = "%3Chello%3E%20&%20%3Cscriban%3E"
wget(url)
Retrieves the content of the following URL by issuing a HTTP GET request.
url
: The URL to retrieve the content for.An object with the result of the request. This object contains the following members:
version
: the protocol of the version.code
: the HTTP return code.reason
: the HTTP reason phrase.headers
: the HTTP returned headers.content
: the HTTP content. Either a string if the mime type is text/*
or an object if the mime type is application/json
otherwise it will return a bytebuffer.>>> wget "https://markdig.azurewebsites.net/"
# wget("https://markdig.azurewebsites.net/")
out = {version: "1.1", code: 200, reason: "OK", headers: {"Content-Type": "text/plain; charset=utf-8", "Content-Length": 0}, content: ""}