Backstory:
You enjoy your new programming job at a mega-multi-corporation. However, you aren't allowed to browse the web since your computer only has a CLI. They also run sweeps of all employees' hard drives, so you can't simply download a large CLI web browser. You decide to make a simple textual browser that is as small as possible so you can memorize it and type it into a temporary file every day.
Challenge:
Your task is to create a golfed web browser within a command-line interface. It should:
- Take a single URL in via args or stdin
- Split the
directory
andhost
components of the URL - Send a simple HTTP request to the
host
to request the saiddirectory
- Print the contents of any
<p>
paragraph</p>
tags - And either exit or ask for another page
More Info:
A simple HTTP request looks like this:
GET {{path}} HTTP/1.1
Host: {{host}}
Connection: close
\n\n
Ending newlines emphasized.
A typical response looks like:
HTTP/1.1 200 OK\n
<some headers separated by newlines>
\n\n
<html>
....rest of page
Rules:
- It only needs to work on port 80 (no SSL needed)
- You may not use netcat
- Whatever programming language is used, only low-level TCP APIs are allowed (except netcat)
- You may not use GUI, remember, it's a CLI
- You may not use HTML parsers, except builtin ones (BeautifulSoup is not a builtin)
- Bonus!! If your program loops back and asks for another URL instead of exiting, -40 chars (as long as you don't use recursion)
- No third-party programs. Remember, you can't install anything.
- code-golf, so the shortest byte count wins
import webbrowser;webbrowser.open(url)
\$\endgroup\$