text:
Debunking Stroustrup's debunking of the myth “C++ is for large, complicated, programs only”
Stroustrup has recently posted a series of posts debunking popular myths about C++. The fifth myth is: “C++ is for large, complicated, programs only”. To debunk it, he wrote a simple C++ program downloading a web page and extracting links from it. Here it is:
#include <string>
#include <set>
#include <iostream>
#include <sstream>
#include <regex>
#include <boost/asio.hpp>

using namespace std;

set<string> get_strings(istream& is, regex pat)
{
    set<string> res;
    smatch m;
    for (string s; getline(is, s);)  // read a line
        if (regex_search(s, m, pat))
            res.insert(m[0]);              // save match in set
    return res;
}

void connect_to_file(iostream& s, const string& server, const string& file)
// open a connection to server and open an attach file to s
// skip headers
{
    if (!s)
        throw runtime_error{ "can't connect\n" };

    // Request to read the file from the server:
    s << "GET " << "http://" + server + "/" + file << " HTTP/1.0\r\n";
    s << "Host: " << server << "\r\n";
    s << "Accept: */*\r\n";
    s << "Connection: close\r\n\r\n";

    // Check that the response is OK:
    string http_version;
    unsigned int status_code;
    s >> http_version >> status_code;

    string status_message;
    getline(s, status_message);
    if (!s || http_version.substr(0, 5) != "HTTP/")
        throw runtime_error{ "Invalid response\n" };

    if (status_code != 200)
        throw runtime_error{ "Response returned with status code" };

    // Discard the response headers, which are terminated by a blank line:
    string header;
    while (getline(s, header) && header != "\r")
        ;
}

int main()
{
    try {
        string server = "www.stroustrup.com";
        boost::asio::ip::tcp::iostream s{ server, "http" };  // make a connection
        connect_to_file(s, server, "C++.html");    // check and open file

        regex pat{ R"((http://)?www([./#\+-]\w*)+)" }; // URL
        for (auto x : get_strings(s, pat))    // look for URLs
            cout << x << '\n';
    }
    catch (std::exception& e) {
        std::cout << "Exception: " << e.what() << "\n";
        return 1;
    }
}

Let's show Stroustrup what small and readable program actually is.

Download http://www.stroustrup.com/C++.html

List all links:
 http://www-h.eng.cam.ac.uk/help/tpl/languages/C++.html
 http://www.accu.org
 http://www.artima.co/cppsource
 http://www.boost.org
 ...

You can use any language, but no third-party libraries are allowed.
Winner
C++ answer won by votes, but it relies on a semi-third-party library (which is disallowed by rules), and, along with another close competitor Bash, relies on a hacked together HTTP client (it won't work with HTTPS, gzip, redirects etc.). So Wolfram is a clear winner. Another solution which comes close in terms of size and readability is PowerShell (with improvement from comments), but it hasn't received much attention. Mainstream languages (Python, C#) came pretty close too.
Comment on subjectivity
The most upvoted answer (C++) at the moment votes were counted was disqualified for not following the rules listed here in the question. There's nothing subjective about it. The second most upvoted question at that moment (Wolfram) was declared winner. The third answer's (Bash) "disqualification" is subjective, but it's irrelevant as the answer didn't win by votes at any point in time. You can consider it a comment if you like. Furthermore, right now the Wolfram answer is the most upvoted answer, the accepted one, and is declared winner, which means there's zero debate or subjectivity.

Comments purged as they were all either obsolete or off-topic.

Clarification: Shall the list of links be as incomplete as Stroustrup's one, i.e. skip any non-http-links that don't include www (including the https, ftp, local and anchor ones on that very site) and report false-positives, i.e. non-linked mentions of http:// as well (not here, but in general)?

Why is pointing out that ALL of the posted answers don't apply to what the OP asked, obsolete or off-topic?

To each his own, I've been called worse. If the OP's goal wasn't to try and somehow prove that Stroustrup is wrong, then I'd agree with your assessment. But the entire premise of the question is to show how "your favorite language" can do the same thing as this 50 lines of C++ in much less lines of code. The problem is that none of the examples do the same thing. In particular, none of the answers perform any error checking, none of the answers provide reusable functions, most of the answers don't provide a complete program. The Stroustrup example provides all of that.

What's sad is his web page isn't even valid UTF-8. Now I've gotta work around that, despite his server advertising Content-Type: text/html; charset=UTF-8... I'm gonna email him.

I wish I'd thought of coming here and asking this question when I read that piece. Certainly C++ is better than it was in the past, but it's by no means optimal.

@Dunk The other examples don't provide reusable functions because they accomplish the entire functionality of those functions in a single line and it makes no sense to make that a whole function on its own, and the C++ example doesn't perform any error checking that isn't handled natively in almost an identical manner, and the phrase "complete program" is almost meaningless.

"You can use any language, but no third-party libraries are allowed." I don't think that's a fair requirement considering boost/asio is used up there which is a third-party library. I mean how will languages that don't include url/tcp fetching as part of its standard library compete?

@greatwolf They don't. That's the point.

@Jason - upvote for "C++ example doesn't perform any error checking that isn't handled natively in almost an identical manner".

Virtually all the answers fail the task (including the original lol) because they don't pick up relative links! I did mine herE: http://forum.dlang.org/thread/tqegmjcofcnwapqitrdo@forum.dlang.org#post-nxcpwmyjfbfbjxqtmrzd:40forum.dlang.org

Is nobody gonna talk about using regexes to parse HTML? Really? I mean Stroustrup does it himself but at least his regex doesn't rely on the HTML-attribute using " and only ever " to delimit its value. 9 out of 10 answers here would fail on <a href='http://htmlparsing.com/regexes.html'>

@funkwurm Problems with the provided solutions have been mentioned many times, you just need to look through comments. The famous "parsing HTML with regex" answer from SO has been brought up too. Many comments have been removed by the mod though.

@undergroundmonorail BF++ does. It is giving me strange and deviant thoughts.

I have to admit, I'm surprised by Stroustrup's claim that most people believe that C++ is used for large programs. I (probably incorrectly) believe the opposite - that for large programs, it's worthwhile to use a language like Java or C# that makes it harder to shoot yourself in the foot!

Its a little odd to me that Stroustrup's challenge is to write C++ code that imports no third party code and the first line (or so, I'm not going to page back and lose my post thus far) is an import of boost's asio library. It kind of makes OP's opinion suspect. But in any case, comparing different languages in this task is very much like comparing apples and oranges. It doesn't really make much sense to use a hammer to tap in a pin, but it can be done; it doesn't make much sense to write assembly code to extract url's from a web page but it can be done. I suspect you could write a RoR program

He's... parsing... html... with... regex... twitch

This code snippet appears in a hacking scene on the Netflix series "Limitless"; Season 1, Episode 10, ~13:05. Proof: http://i.imgur.com/7a16H8y.png

I'm casting a close vote as lacking an objective winning criterion because the question is tagged [tag:popularity-contest], but the "winner" paragraph at the end suggests the OP is subjectively disqualifying answers.

@pppery I really wonder what are you trying to achieve by closing this question.

@pppery The most upvoted answer (C++) at the moment votes were counted was disqualified for not following the rules listed in question. There's nothing subjective about it. The second most upvoted question at that moment (Wolfram) was declared winner. The third answer's (Bash) "disqualification" is subjective, but it's irrelevant as the answer didn't win by votes at any point in time. You can consider it a comment if you like. Furthermore, right now the Wolfram answer is the most upvoted answer, the accepted one, and is declared winner, which means there's zero debate or subjectivity.

@pppery Does that mean that if the OP edited out the “Winner” section and just left the answer accepted without any comments the question would have an objective winning criteria? I agree with the OP here, pop-con is objective, and “no third party libraries”, while not a great thing to ban, still disqualifies the C++ answer, making the Wolfram answer the clear winner. Flag the C++ answer in invalid and deletion, don’t close the question because of one bad (debatable but not my point) answer

OK, you've convinced me. I'll vote to re-open as soon as the C++ answer is deleted by a moderator (which should have been done in the first place rather than disqualifying it from the winning criteria)

And my flag was resolved without the answer being deleted, so this question is now in a chicken-egg situation leaving no resolution other than remaining closed.

@pppery What rule do you follow exactly that says to close a question if one answer violates its rules? Besides closing a question for zero practical reasons other than virtual points, all you have achieved is wasting of time. You can't reopen the question anyway, you aren't a mod.

Wolfram
This feels like complete cheating
Import["http://www.stroustrup.com/C++.html", "Hyperlinks"]

So just add some honest parsing on top
Cases[
 Import["http://www.stroustrup.com/C++.html", "XMLObject"],
 XMLElement["a", {___, "href" -> link_, ___}, ___] :>
  link /; StringMatchQ[link, RegularExpression["((http://)?www([./#\\+-]\\w*)+)"]]
, Infinity]

Nope, I don't see any cheating here. This challenge is about bringing out the best of your language. And that first line is the epitome of "small and readable".

An answer that can ignore the silly arguments about catching ftp links.  Brilliant.

Came here to offer this exact solution, pleased to see others have appreciated it as well.

@MartinBüttner In that case you might want to consider downvoting http://meta.codegolf.stackexchange.com/a/1078/12130

@DavidMulder Who says I didn't? ;)

@MartinBüttner Ah, if you're aware of it then you should probably enforce the community consensus though~ (and try to change the consensus if you feel so inclined).

@DavidMulder Technically, the loophole is currently not valid, since the vote breakdown is +41/-21 (and the loophole question states that loopholes are accepted if there are at least twice as many upvotes as downvotes). A close call, admittedly, but still. ;) Furthermore, this is a popularity contest, not a code golf, and in particular, it's a pop-con about showing how easily this can be done in a given language, which is why I think the loophole doesn't really apply to this challenge anyway (since the challenge basically asks for it).

@MartinBüttner Oh nice~, I couldn't check that. Sooo, is anything stopping people right now from adding a purpose build function to their codegolf language forks for each new question? That seems the 'sensible' next step in that case~ (It's the problem I have with most of these challenges, languages like OpenEdge, ColdFusion and Wolfram are what I tend to call framework languages, because they contain not just a language itself, but also very high level purpose build languages you would normally find in frameworks and/or libraries. The true strength of a language is not in the number of

purpose build functions, but in the easy of access to such a function if you need it. For example with node.js this would be a npm install jsdom call, whereas with Mathematica you have to search the interwebs for the libraries you need).

@DavidMulder That's a different issue. Only languages (and language versions) which were available before a challenge was posted, may be used in that challenge. If you want to discuss this further, feel free to join us in chat.

@MartinBüttner: Actually, it's bashing C++ for not declaring "everything and the kitchen sink" to be part of the standard library, and thus making it unsuitable for really small devices, restricted environments, and other situations...

I suppose, this Import statement does true Html parsing rather than the original code’s naive regex matching. So it’s not equivalent. It’s closer to what you likely want in real life, but still, not doing the same as the original…

C++
#include <boost/asio.hpp>
#include <regex>
#include <iostream>
int main() {
    std::string server = "www.stroustrup.com";
    std::string request = "GET http://" + server + "/C++.html HTTP/1.0\r\nHost: " + server + "\r\n\r\n";
    boost::asio::ip::tcp::iostream s{server, "http"};
    s << request;
    std::regex pat{R"((http://)?www([./#\+-]\w*)+)"};
    std::smatch m;
    for (std::string l; getline(s, l);)
        if (std::regex_search(l, m, pat))
            std::cout << m[0] << "\n";
}

The main shortcoming is the awkward nature of boost::asio, I'm sure it can be even shorter with a better library.

I think using boost is fair, since large parts of it have been integrated into the standard library in the past, and there have been plans to integrate asio in a future version.

What about ftp://ftp.research.att.com/pub/c++std/WP/CD2 and https://www.youtube.com/watch?v=jDqQudbtuqo&feature=youtu.be?

using std::string; would somewhat simplify the code (and will make the long line short enough so as not to require the horizontal scrolling bar).

@DevSolar You can consider boost a part of the standard library for C++ if you wish, it's a staging area for the standard library anyway. However, even with boost, you still have to know inner workings of HTTP protocol. It may look simple in this sample, but imagine you need to support HTTPS, gzip, redirects etc. Will it be as simple? Bare TCP socket quickly becomes insufficient.

you don't need Host header in HTTP/1.0

"even shorter with a better library" well naturally if the library offers a importHyperLinks(std::string url) function.

Pure Bash on Linux/OS X (no external utilities)
HTTP client software is notoriously bloated.  We don't want those kinds of dependencies.  Instead we can push the appropriate headers down a TCP stream and read the result.  No need to call archaic utilities like grep or sed to parse the result.
domain="www.stroustrup.com"
path="C++.html"
exec 3<> /dev/tcp/$domain/80
printf "GET /$path HTTP/1.1\r\nhost: %s\r\nConnection: close\r\n\r\n" "$domain" >&3
while read -u3; do
    if [[ "$REPLY" =~ http://[^\"]* ]]; then
        printf '%s\n' "$BASH_REMATCH"
    fi
done

Meh - I suppose it could be more readable...

Like this one using unix file handles for the pipes.

Wow, never thought one can do this without external utils. Although it seems my bash 3.2.17 on LFS is a tiny bit obsolete so that doesn't support mapfile :)

@Ruslan Yep, mapfile comes with bash 4.x.  The same thing is totally doable with a while read loop as well.

@Ruslan I changed it to while read instead of mapfile.  More portable and more readable, I think.

Works on OS X, too!

Very nice.  I think it fails when you have two links on the same line though.  Also sadly the original link now redirects to https.

Python 2
import urllib2 as u, re
s = "http://www.stroustrup.com/C++.html"
w = u.urlopen(s)
h = w.read()
l = re.findall('"((http)s?://.*?)"', h)
print l

Lame, but works

Why not chain a lot of those calls? l = re.findall('"((http)s?://.*?)"', u.urlopen(s).read())

It is short but it is not idiomatic (readability counts in Python)

Hmmm...if all my code ignored errors like this example then 75% to 90% of my work would already be done on every project I work on.

What about ftp://ftp.research.att.com/pub/c++std/WP/CD2? And the output is not a plain list but a list of tuples...

@TobiasKienzler the reference C++ code doesn't catch the ftp urls either.

@jwg Indeed. I asked for clarification on that. Generalizing the regex shouldn't be too difficult, nonetheless I prefer avoiding regex in this case...

@Dunk: Suppose the example did catch some exception (e.g. from urlopen()).  What should it do with such an exception, other than crash and die?  If it's going to crash and die anyway, why not just let Python handle the crashing-and-dying, and leave off the exception handling altogether?

@Kevin:My nit is that this answer (and none of the others) answer the OP's challenge as asked. The Stroustrup code example does more than the answers. This gives the misleading appearance that the answers can do the same thing in less lines of code. The fact is that none of the answers are doing the same as the original code. So it isn't an apples to apples comparison. As for why not let Python handle the crashing and dying, because someone might actually want to use the code in an actual program. Stroustrup's example code allows one to do so.

@Dunk: If I were using somebody else's Python code, I'd much rather they not catch urlopen errors than (say) catch them and call sys.exit("something's borked!").  If they do the latter, I have to catch SystemExit, which is never fun.

you don't need (http) to be in a group.(https?://.*?) works just as well

Use raw strings in RegEx.

C#
using System;
using System.Net;
using System.Text.RegularExpressions;

string html = new WebClient().DownloadString("http://www.stroustrup.com/C++.html");
foreach (Match match in Regex.Matches(html, @"https?://[^""]+"))
    Console.WriteLine(match);

You can use var html, and probably var match to shave off a few characters.

@Superbest I can make names single-character and get rid of html variable altogether too, but it's not what I'm after.

@Superbest not [tag:code-golf]. :D

Well, it improves readability, too. Is there ever a reason not to use var when it won't impact code semantics?

@Superbest: "it improves readability" is subjective. Personally, I think explicitly stating the type of the variable improves readability (usually, like in this code here). I don't want to debate this, though; I just want to point out that alternative views exist.

If you don't know what object type is returned by a method "var" makes reading other peoples code (exploring libraries unknown to you) more difficult and time consuming. Say you read "var name = GetName()". Is it a string? Or something else? You can't know without checking.

But var actually says "don't care", so the GetName() may change the return type to an unrelated one, as long as it still gives me what I am looking for.

@Superbest you can't use var for Match anyway, since MatchCollection only implments ICollection. This is a major PITA if you ask me, and GetEnumerator can't be changed without breaking changes.

@LucasTrzesniewski var can be used in this sample, you'll get object, which is sufficient for Console.WriteLine.

@Athari oh right, I didn't read carefully enough

If you care about the use of var go here. http://stackoverflow.com/questions/41479/use-of-var-keyword-in-c-sharp

Personally I think this code is more readable than some of the other answers, even if it's not as short.

With the latest C#, you can omit class and function Main.

@Vlad Improved my answer, thanks. However, with high-ranked users closing the question for purely subjective reasons (I mean, nobody likes admitting that every question is technically a [tag:popularity-contest], but come on), I don't think there's much point in improving answers to the question which will receive very few views.

"No third-party" is a fallacy
I think the "no third-party" assumption is a fallacy. And is a specific fallacy that afflicts C++ developers, since it's so hard to make reusable code in C++.  When you are developing anything at all, even if it's a small script, you will always make use of whatever pieces of reusable code are available to you.
The thing is, in languages like Perl, Python, Ruby (to name a few), reusing someone else's code is not only easy, but it is how most people actually write code most of the time.
C++, with its nearly impossible-to-maintain-compatible-ABI-requirements makes that a much tougher job, you end up with a project like Boost, which is a monstrous repository of code and very little composability outside it.
A CPAN example
Just for the fun of it, here goes a CPAN-based example, with proper parsing of the html, instead of trying to use regex to parse html
#!/usr/bin/perl
use HTML::LinkExtor;
sub callback {
   my ($tag, %links) = @_;
   print map { "$_\n" } values %links
}
$p = HTML::LinkExtor->new(\&callback, "http://www.stroustrup.com/C++.html");

That HTML answer, funny as it is, is a fallacy. "HTML is not a regular language and hence cannot be parsed by regular expressions." is true, but HTML tags definitely are a regular language, and something to turn a stream into bite-sized chunks of tags and text nodes would serve a similar purpose to a lexer. Reminds me of that supposed monster regex purportedly necessary for parsing email addresses, when what it's actually parsing is a different RFC822 element than the one we generally consider to be an email address.

From the point of view of a Perl hacker, the entire CPAN is part of Perl's standard library :)

Upvote for addressing the point of the 3rd party libs, but: crap, making reusable code in C++ is as easy cheesy as in other language. Using and especially finding reusable code may be a tad harder, but the only thing that's seriously problematic is reusing compiled artifacts, but that's often a non-issue in interpreted languages like Perl, etc.

To stretch an analogy, Boost is more like CPAN - pick and choose. You don't call CPAN a "monstrous repository of code" just because there's such a lot of stuff in there you don't use?

CPAN is a 'monstrous repository of code', by any reasonable definition of those four words.

That's not necessarily a bad thing.  :)  As long as you can pick and choose, at least.

@MartinBa I disagree, C++ being a compiled language, requiring every executable to rebuild its full stack of dependencies because it's hard to maintain ABI compatibility seriously hinders code reusability. In order to produce a reusable library in C++ you have to go through really long lengths in order to make sure you don't force yourself into ABI-incompatible changes all the time.

@jwg the difference is that CPAN is extremely composable, not only you're allowed to pick and choose which libraries to use, but they're usually made compatible against different versions of their dependencies (and the cpantesters help ensure that is true).
With Boost you may select to use just a portion of it, but you have to use it all from the same version.

You're missing a backslash on your callback.

But if you allow third-party libraries in this contest then every answer becomes thirdPartyLibraryIJustMade.getStroustrupLinksAndPrintThem()

@DanielRuoso - why does "producing a reusable library" entail any compilation for you? If the library just provides source code files, it is still a reusable library, isn't it?

@MartinBa because having to rebuild the whole universe everytime you want to implement a simple task is unbearable.

You have to do something to rule out third-party code, because otherwise every program in every language comes out as a one-liner (plus include and main boilerplate and whatnot), because you write a third-party module that does exactly what's asked for, publish it, and use it in "your program". The tricky question is how to draw the line in order to get a reasonable comparison between programming languages, and that in turn depends on the purpose of the comparison. Stroustrup opted not to use a proper HTTP client, which would be a most peculiar decision in real code.

@SteveJessop I disagree. I have implemented and published CPAN modules for particular tasks before and those became usable by someone else. When I started this example, I searched for HTML::Parser, I didn't even know the module for extracting the links existed, but apparently extracting the links is a common-enough problem that someone went through the trouble of posting a reusable module that does just that.
This is a fundamental aspect of the programming language, and a part where other languages (Perl in particular, but also Python and Ruby) are really good at, and C++ is really poor at.

@DanielRuoso: I mean that if Stroustrup put that code on github with a different name for the main() function, would you then accept that it's possible to download a webpage and extract the links in C++ in one line, that one line being int main() { return stroustrups_thingy(); }? Much more concise than your Perl code. Now, my C++ one-liner rather shamelessly uses a third-party library intended for the purpose of rigging this benchmark, but you think that no restrictions on doing that are needed in order to make meaningful comparisons between languages, right? ;-)

... so in the end all languages are equally concise at doing anything, because all the details required to do anything can be hidden away in a benchmark-rigger library. It's like forking CJam for a particular code golf challenge so that it solves that challenge in one character. You don't have to ban it, but if you don't ban it you know what will happen.

Still, I like your solution since it points out that presumably without intending to, Stroustrup chose an example challenge that a Perl programmer wouldn't even have to address, using that CPAN module instead, since precisely the same problem has been solved before and the solution published. But if a Perl programmer did choose to address it, OK, we can look at the source of the module if we want to see how wordy it is.

@SteveJessop the problem is that in C++ the amount of reusable code is just not as large: see http://stackoverflow.com/questions/822581/what-c-library-should-i-use-to-implement-a-http-client  http://www.mostthingsweb.com/2013/02/parsing-html-with-c/

Mojolicious would also allow something like use Mojo::UserAgent; say for Mojo::UserAgent->new->get("http://www.stroustrup.com/C++.html")->res->dom->find("a[href^=http]")->map(attr => "href")->each

(linebreaks could easily be added, outside of the context of an SO comment box)

UNIX shell
lynx -dump http://www.stroustrup.com/C++.html | grep -o '\w*://.*'

Also finds an ftp:// link :)
Another way, without relying on :// syntax:
lynx -dump -listonly http://www.stroustrup.com/C++.html | sed -n 's/^[ 0-9.]\+//p'

I can't work out whether to +1 because using a web browser to download a web page is the right tool for the job or to -1 because the challenge is to write a program to do blahblahblah and you just called a program to do the blahing.

@DavidRicherby Arguably, a web browser is the right tool to view a webpage. The right tool to download a webpage is an http request. Either way, this solution is fun!

I think it's better to replace lynx with curl or wget. They are more commonly used to download a webpage.

@PavelStrakhov I chose lynx exactly because it can dump the links without me doing anything special :)

@Ruslan: that's OK, Stroustrup's code doesn't do anything special with the html either. He just regexes it for urls, which doesn't require lynx :-)

@SteveJessop by "special" I mean actually parsing or regexing or whatever. With lynx I just grep out the list of links (which curl and wget don't list) and remove the numbering. You may consider it cheating or whatever, but I thought it's fun to {use the tool which almost perfectly does what is required}, just fine-tuning the output.

@Ruslan: possibly my snark at Stroustrup's code wasn't strong enough! He doesn't extract links (like lynx does), he extracts URLs. Compared with his, your code "misses" any URLs in the text that aren't links. Which normally would be a feature in your code and a bug in his, but he set the problem so maybe not :-) Not that there are any such urls on that page at the moment.

Yeah, I know, is not [tag:code-golf], but both grep and sed is an overkill. lynx -dump http://www.stroustrup.com/C++.html | grep -o '\w*://.*'

@manatwork thanks, this is much nicer. I indeed wanted to use one filter, but didn't know of -o option. Edited to include this improvement.

"but no third-party libraries are allowed".  I contend that lynx is functionally equivalent to a third-party library in this scenario.

CSS 3
* {
  margin: 0;
  padding: 0;
}
*:not(a) {
  font: 0/0 monospace;
  color: transparent;
  background: transparent !important;
}
a {
  content: "";
}
a[href*="://"]::after {
  content: attr(href);
  float: left;
  clear: left;
  display: block;
  font: 12px monospace;
  color: black;
}

This code can be used as a user style to display only absolute links on a page in an unformatted list. It may not work correctly if your browser enforces minimum font size.
It works correctly with http://www.stroustrup.com/C++.html (note !important on background). In order to work on other pages with more styles, it must be extended (reset more properties, mark properties as important etc.).
Alternative version which includes relative links except intrapage links starting with hashes (it relies on a hard-coded absolute link, unfortunately):
* {
  margin: 0;
  padding: 0;
}
*:not(a) {
  font: 0/0 monospace;
  color: transparent;
  background: transparent !important;
  float: none !important;
  width: auto !important;
  border: none !important;
}
a {
  content: "";
}
a::after {
  display: none;
}
a:not([href^="#"])::after {
  content: attr(href);
  float: left;
  clear: left;
  display: block;
  font: 12px monospace;
  color: black;
}
a:not([href*="://"])::after {
  content: "http://www.stroustrup.com/" attr(href);
}

This is the worst thing I've ever seen. +1

This is beautiful and completely horrifying. +1

Clojure
(->> (slurp "http://www.stroustrup.com")
     (re-seq #"(?:http://)?www(?:[./#\+-]\w*)+"))

Slurp?! I need to learn Clojure.

@11684 - Clojure also has standard functions named spit, zipper, and lazy-cat... :-)

Wow, I think that's gonna be a late New Year's Resolution. @BobJarvis

Emacs Lisp
(with-current-buffer (url-retrieve-synchronously "http://www.stroustrup.com/C++.html")
  (while (re-search-forward "https?://[^\\\"]*")
    (print (match-string 0))))

I'm a little dissapointed, given how compact and eminently readable this code is, that it does not have more votes.  Well done.

Scala
"""\"(https?://.*?)\"""".r.findAllIn(scala.io.Source.fromURL("http://www.stroustrup.com/C++.html").mkString).foreach(println)

pack everything in one line - C++ can do it too

What about ftp://ftp.research.att.com/pub/c++std/WP/CD2?

@quetzalcoatl - This is one expression, not just one line. You can just delete all of the line breaks from the C++ code, but that's not the same thing as doing the whole task in a single expression.

@DaoWen: Sorry, but starting expressions-vs-line is just going silly. Add some functors and C++ you can do it too. But that's just the question of what libs are considered to be "granted" and have "zero code inside". It doesn't change the fact that packing it into a line hurst readability. One can keep it still as a single expression and just reformat it into a few lines to gain much and loose nothing other than .. line count. That's my point. Silly packing - C++ can do it too. If someone wants to get out of the "silly packing" box, then should format the code for readability, not linecount.

But, here's my sin there, I should have written my point clearly right away, and not try to just drop a punchline. Every day everyone learns a thing, thanks for making me think about that, DaoWen!

@TobiasKienzler: link seems broken, could you recheck?

@quetzalcoatl Tobias didn't put the link there for us to follow it. He was asking the writer of this answer why it wasn't in his results.

You can't pack everything on one line in C++, if you have any #include, etc, you can't.

I tried compiling a one-liner C++ program..
prog.cpp:1:21: warning: extra tokens at end of #include directive
#include  using namespace std; int main() { return 0; }
^
/usr/lib/gcc/i586-linux-gnu/4.9/../../../i386-linux-gnu/crt1.o: In function _start': (.text+0x18): undefined reference to main'
collect2: error: ld returned 1 exit status

PHP 5
<?php
preg_match_all('/"(https?:\/\/.*?)"/',file_get_contents('http://www.stroustrup.com/C++.html'),$m);
print_r($m[1]);

Suggested edits: '/"((http)s?://.*?)"/' ⇒ '|"((http)s?://.*?)"|' (currently an error); remove array_unshift($m); (currently an error, you likely meant array_shift instead); print_r($m); ⇒ print_r($m[1]); (only output the urls).

fixed, thanks for your input

@DavidXu Except you didn't fix it...?

now its fixed.!

PowerShell
Text search for all fully-qualified URLs (including JavaScript, CSS, etc.):
[string[]][regex]::Matches((iwr "http://www.stroustrup.com/C++.html"), '\w+://[^"]+')

Or to get links in anchor tags only (includes relative URLs):
(iwr "http://www.stroustrup.com/C++.html").Links | %{ $_.href }

Shorter versions from comments:
(iwr "http://www.stroustrup.com/C++.html").Links.href

(iwr "http://www.stroustrup.com/C++.html").Links.href-match":"

If anyone wonders, iwr is an alias for Invoke-WebRequest (PS3+).

You could abuse PowerShell's eagerness to flatten collections and do: (iwr "http://www.stroustrup.com/C++.html").Links.href (or (iwr "http://www.stroustrup.com/C++.html").Links.href-match":" for only absolute URI's)

That's pretty handy!

D
import std.net.curl, std.stdio;
import std.algorithm, std.regex;

void main() {
foreach(_;byLine("http://www.stroustrup.com/C++.html")
    .map!((a)=>a.matchAll(regex(`<a.*?href="(.*)"`)))
    .filter!("a")){ writeln(_.front[1]); }
}

To make the list similar to the original example, you could pipe the program's output through | sort | uniq or instead add import std.array and change the line .filter!("a")){ writeln(_.front[1]); } into this: .filter!("a").map!(a => a.front[1]).array.sort.uniq){ writeln(_); }.  Note, however, that I have only tried this code and not proved it to be correct or "idiomatic". :)

Node.js
var http = require('http');

http.get('http://www.stroustrup.com/C++.html', function (res) {
    var data = '';
    res.on('data', function (d) {
        data += d;
    }).on('end', function () {
        console.log(data.match(/"https?:\/\/.*?"/g));
    }).setEncoding('utf8');
});

I wonder if require('http').get works. If it does then we can ditch the var statement and shorten another line.

@Unihedro It does.

@Unihedro It does, but this isn't a golfing contest.

You don’t need to use any capturing groups.

I think it's JavaScript rather than a framework name.

Haskell
Some troubles with "\w" in Text.Regex.Posix
import Network.HTTP
import Text.Regex.Posix
pattern = "((http://)?www([./#\\+-][a-zA-Z]*)+)"
site = "http://www.stroustrup.com/C++.html"

main = do
    file <- getResponseBody =<< simpleHTTP (getRequest site)
    let result = getAllTextMatches $ file =~ pattern
    putStr $ unlines result -- looks nicer

Why is the type of result specified explicitly? It should be fully constrained by its use in unlines.

This does stretch the rules a bit, seeing as neither Network.HTTP nor TextRegex.Posix are in the base package. (Though they are in the Haskell Platform, and of course on Hackage, so...)

@JanDvorak, I start to write in ghci (probably i should post it unchanged). But your note is relevant, thanks.

@leftaroundabout, did not know. It looks like I could not have done, if had used the base package.

network isn't in base either, so save for rolling your own socket bindings there's no practical way to do it with just base.

Ruby
require 'net/http'
result = Net::HTTP.get(URI.parse('http://www.stroustrup.com/C++.html'))
result.scan(/"((http)s?://.*?)"/)

Your regex will fail, you need to use %r{"(https?://[^"]+)"}. Also you can use Net::HTTP.get('www.stroustrup.com', '/C++.html') to shorten up request (and keep it readable). So whole code can be in one line (keeping it readable): puts Net::HTTP.get("www.stroustrup.com", "/C++.html").scan(%r{"(https?://[^"]+)"}). Run it with ruby -rnet/http and you don't even need require 'net/http' line.

PHP
As far as I can tell, most modern PHP installations come with DOM processing, so here's one that actually traverses the anchors inside the HTML:
foreach (@DOMDocument::loadHTMLFile('http://stroustrup.com/C++.html')->getElementsByTagName('a') as $a) {
    if (in_array(parse_url($url = $a->getAttribute('href'), PHP_URL_SCHEME), ['http', 'https'], true)) {
        echo $url, PHP_EOL;
    }
}

The inner loop could be shortened to:
preg_match('~^https?://~', $url = $a->getAttribute('href')) && printf("%s\n", $url);

Actually wanted to come up w this (as my first answer here). You did it first, so here's your +1 (for not using an error prone Regex)! Hint: You could use a lame 1 instead of the true for the in_array strict search. You can as well omit the brackets. I'm not completely sure, but iirc you could as well drop the http and only leave the :// (go w/o the scheme). .

And: Another possibility would be to drop the if ( ) {} in favor of in_array() and print $url.PHP_EOL. But yeah, you would get another +1 (if I could) for best readability :)

Just tried your example and got an error for strict standards (PHP 5.4). Seems like in the source, there's somewhere a corrupted or wrongly formatted link with a missing semicolon. You could turn off error reporting by using @\DOMDocument. Just tried that and can confirm it works.

Nah, it's the documentation that's wrong; technically you're not supposed to call ::loadHTMLFile() statically, and adding @ only hides that artefact.

Yeah, that's the thing I know. I just didn't make myself clear: Both errors (strict and missing semicolon) aren't related. Just do the DOM loop line by line to see for yourself. You can set  error_reporting( E_ALL ^ E_STRICT ); and the error still is there. Edit: Here's a Gist to play around with. Just remove the @/error suppression from the loadHTMLFile() call. :)

Although they're not strictly related, the silencing operator "fixes" both issues; also, the target HTML document is crap :P

This is definitely one of the most "correct" solutions, one of the only ones I could see in use in production. nice job

Unix Shell
wget -q -O - http://www.stroustrup.com/C++.html | sed -n '/http:/s/.*href="\([^"]*\)".*/\1/p' | sort

Though i have to admit this doesn't work if there's more than one link on a line.

curl http://www.stroustrup.com/C++.html saves a few characters.

"but no third-party libraries are allowed".  I guess since wget is GNU (as is bash), you could argue that it is not third-party.  But curl definitely is third-party.

What about ftp://ftp.research.att.com/pub/c++std/WP/CD2 and https://www.youtube.com/watch?v=jDqQudbtuqo&feature=youtu.be?

@TobiasKienzler I guess Stroustrup's original code doesn't find them either

Java
import java.util.regex.*;
class M{
    public static void main(String[]v)throws Throwable{
        Matcher m = Pattern.compile( "\"((http)s?://.*?)\"" )
            .matcher(
                 new Scanner(
                         new URL( "http://www.stroustrup.com/C++.html" )
                             .openStream(),
                         "UTF-8")
                     .useDelimiter("\\A")
                     .next());
        while(m.find())
            System.out.println(m.group());
    }
}

Could you properly format code in your answers? It isn't competition for the least readable code. You can format it to avoid horizontal scrollbars at least.

If you use a Scanner you can make it processing the regex pattern for links directly and iterate over the Scanner’s results.

Yep .. that's java for you.  Using it for code golf is a brave undertaking.

Never thought I'd see a java solution that's actually shorter than C++!

Good job, but I think it can be made less verbose with some lambdas.

Correction to my last comment: I must admit this is pretty much the shortest and cleanest code that can be written in Java. I've tried a SAX parser approach, which could be made even shorter with lambdas, but the web page is not XHTML and the parser throws exceptions. Regex is the only way to go.

If you can use JSoup, you can make it nicer still, but I don't know what the rules are around using external libraries for this.

@javadba Java is not worse than other languages, it only needs to be used correctly. As hinted in my old comment, this answer is abusing the tool which can do the entire job for just getting the entire page as string, followed by unnecessary manual regex matching. With recent Java versions you can do it like: new Scanner(new URL("http://www.stroustrup.com/C++.html").openStream(), "UTF-8") .findAll("\"(https?://.*?)\"").forEach(m -> System.out.println(m.group(1))); though real code would use try(…) for cleanup…

Groovy
"http://www.stroustrup.com/C++.html".toURL().text.findAll(/https?:\/\/[^"]+/).each{println it}

Could be improved by using ?. operator to avoid NPEs?

@ChrisKaminski and be the first (beside Bjarne) around here to check for errors?  never!  beside that: i only see IO related exceptions here.  where do you see a NPE?

findAll() could return null, no?  Or will it return an empty list?  Still a bit new to Groovy.  EDIT:  nm, looks like findAll() returns an empty list.  Those Groovy guys were so smart.  :-)

SQL (SQL Anywhere 16)
Define a stored procedure to fetch the web page
CREATE OR REPLACE PROCEDURE CPPWebPage()
URL 'http://www.stroustrup.com/C++.html'
TYPE 'HTTP';

Produce the result set using a single query
SELECT REGEXP_SUBSTR(Value,'"https?://[^""]+"',1,row_num) AS Link
FROM (SELECT Value FROM CPPWebPage() WITH (Attribute LONG VARCHAR, Value LONG VARCHAR)
      WHERE Attribute = 'Body') WebPage,
      sa_rowgenerator( 1, 256 )
WHERE Link IS NOT NULL;

Limitations: This produces up to 256 links. If more links exist, then bump up the 256 to an appropriate value.

I didn't believe there would be golf in SQL... until now.

I get it ... "links". :-)

CoffeeScript / NodeJS
require('http').get 'http://www.stroustrup.com/C++.html', (r) ->
    dt = '';
    r.on 'data', (d) -> dt += d
    r.on 'end' , (d) -> console.log dt.match /"((http)s?:\/\/.*?)"/g

I guess this is CoffeeScript/Node? I guess you should specify that...

Wow. That's very readable.

@slebetman it definitely is small though

@slebetman Yeah CoffeeScript is so much more readable than JavaScript :) I was glad to get rid of all the curly braces }:)

Perl
use LWP;
use feature 'say';

my $agent = new LWP::UserAgent();
my $response = $agent->get('http://www.stroustrup.com/C++.html');

say for $response->content =~ m<"(https?://.+?)">g;

The code would be more clear if you avoided the field-separator and record-separator variables and just did:
print map { "$_\n" }
$response->content =~ m<"(https?://.+?)">g;

@DanielRuoso agreed.

or even use v5.10; and say for $response->content...

To each his own, I suppose.  Some of the backported perl6 features have been problematic (smart matching, I'm looking at you), but say is quite useful, and in my mind clearer here.  (Also, there have been rather a lot of completely-unrelated-to-perl6ism improvements to perl5 in the last 13 years; it might be worth checking out.)

@MarkReed I agree that say is probably more readable in this case, particularly for those less familiar with perl.

R
html<-paste(readLines("http://www.stroustrup.com/C++.html"),collapse="\n")
regmatches(html,gregexpr("http[^([:blank:]|\\\"|<|&|#\n\r)]+",html))

...although R is written mainly in C... so probably a few lines of C code behind those 2 lines of R code.

That (or something similar) is true for pretty much all the answers here.

Objective-C
NSString *s;
for (id m in [[NSRegularExpression regularExpressionWithPattern:@"\"((http)s?://.*?)\"" options:0 error:nil] matchesInString:(s=[NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://www.stroustrup.com/C++.html"]])]){
    NSLog(@"%@",[s substringWithRange:[m range]]);
}

What? Please write the Swift version. That square bracket nonsense is hurting my eyes :)

Hurray for []!
Also, we should totally add a Smalltalk version ;)

@MisterSmith Swift answer now available here.

Go
package main

import (
    "fmt"
    "io/ioutil"
    "net/http"
    "os"
    "regexp"
)

func main() {
    resp, err := http.Get("http://www.stroustrup.com/C++.html")
    if err != nil {
        fmt.Fprintln(os.Stderr, err)
        os.Exit(1)
    }
    defer resp.Body.Close()
    data, _ := ioutil.ReadAll(resp.Body)
    results := regexp.MustCompile(`https?://[^""]+`).FindAll(data, -1)
    for _, row := range results {
        fmt.Println(string(row))
    }
}

P.S. this code reads entire source into memory, so consider using regexp.FindReaderIndex to search in stream, that'll make the app bulletproof.

Tcl
package require http
set html [http::data [http::geturl http://www.stroustrup.com/C++.html]]
puts [join [regexp -inline -all {(?:http://)?www(?:[./#\+-]\w*)+} $html] \n]

You can get away by doing http::data inside the puts. No need to create a temporary variable. And I'd also format it by putting newlines and indenting at every [. But that's a style choice.

CJam
CJam does not have regex so I had to use a different approach in this one:
"http://www.stroustrup.com/C++.html"g''/'"*'"/(;2%{_"http://"#!\"https://"#!e|},N*

I first convert all ' to ", then I split on all ", take every alternative string and then finally filter that list for strings starting with http:// or https://. After that, simply print each filtered string on a new line.
Try it using the Java interpreter like
java -jar cjam-0.6.2.jar file.cjam

where file.cjam has the contents of the code above.

Don't know about the readable part... didn't know Cjam has web functionality

If you want to golf it... ''/'"f/:+ for ''/'"*'"/'"f/0f=.

...wait why is '"f/0f= there? Is that supposed to do something (2% for instance)?

F#
This code could be far shorter but I would write something like this if I ever expected to have to read or use this code again so it has many unnecessary type annotations.  It demonstrates the use of an active pattern MatchValue to enable pattern-matching against the standard CLR type Match
open System.Net

let (|MatchValue|) (reMatch: Match) : string = reMatch.Value

let getHtml (uri : string) : string =
    use webClient = WebClient() in
        let html : string = webClient.DownloadString(uri)
        html

let getLinks (uri : string) : string list =
    let html : string = getHtml uri
    let matches : MatchCollection = Regex.Matches(html, @"https?://[^""]+")
    let links = [ for MatchValue reMatch in matches do yield reMatch ]
    links

let links = getLinks "http://www.stroustrup.com/C++.html"
for link in links do
    Console.WriteLine(link)

Edit
I made getLinks its own function

I really like how you used type annotations. I think naming values to describe what you return is ok, but name of the function is expressive enough: getHTML and html value, getLinks and links value. Last two lines may be links |> Seq.iter (printfn "%s")

@MichalMa I agree that the name of the function is expressive enough on its own, the html and links variables are there for pragmatic reasons: so there is somewhere to set a breakpoint.  I used the for loop instead of List.iter just because I like the way it reads more, although in a repl I probably would have used List.iter.

Rebol
parse read http://www.stroustrup.com/C++.html [
    any [
        thru {<a href="} copy link to {"} (print to-string link)
    ]
]

Delphi
program Links;
{$APPTYPE CONSOLE}
{$R *.res}
uses
  System.SysUtils, idHTTP, RegularExpressions;
var
  client: TidHTTP;
  match : TMatch;
begin
  client := TidHTTP.Create;
  try
    match := TRegEx.Create('<a(.*)href="(.*)">(.*)<\/a>', [roIgnoreCase, roMultiline])
      .match(client.Get('http://www.stroustrup.com/C++.html'));
    with match do
      while Success do
      begin
        if Groups.Count >= 3 then
          if copy(lowercase(Groups[2].Value), 1, 4) = 'http' then
              writeln(Groups[2].Value);
        match := NextMatch;
      end;
  finally
    client.Free;
  end;
end.

This would work in (I suppose) Delphi XE and later. It requires no component other than those that are already installed in a default setup (namedly indy and regular expressions). Even tho delphi is quite close to C++ in general structure, I guess this task turned out to be a bit shorter.

Ruby
Another Ruby solution:
require 'open-uri'
open('http://www.stroustrup.com/C++.html', 'r:iso-8859-1:utf-8') do |f|
  puts f.read.scan(%r{"(https?://www[^"]*)"}).sort
end

MATLAB
Is quite straightforward with urlread and regexp:
url = 'http://www.stroustrup.com/C++.html';
links = regexp(urlread(url), '<a href="http://([^"]*\.*)">', 'tokens');

Scala
object Downloader extends App {
    val s = io.Source.fromURL("http://www.stroustrup.com/C++.html", "iso-8859-1").mkString // load URL to String
    val regex = """((http://)?www([./#\+-]\w*)+)""".r                                      // create and compile regexp
    println(regex.findAllIn(s).mkString("\n"))                                             // print matches
}

F#
open System.Net
open System.Text.RegularExpressions

let html = (new WebClient()).DownloadString("http://www.stroustrup.com/C++.html") in
    Regex.Matches(html, @"https?://[^""]+") |> Seq.cast<Match> |> Seq.iter (printfn "%A")

Taken from the C# version.

SmallTalk (Pharo 3)

Hurray for []! Also, we should totally add a Smalltalk version ;)

@Bersaelor at Objective-C answer.
I know basics of Smalltalk - syntax of language and some tutorials. I decide that it's good place for practice. I have already installed Pharo 3.0.

but no third-party libraries are allowed

Okay. On downloaded image I found Zinc-HTTP and regex packages.  Probably I should read about "third-party" meaning.
So, code:
(ZnClient new get: 'http://www.stroustrup.com/C++.html')
   regex: '((http\://)?www([./#+-]\w*)+)' matchesDo: [ :x | Transcript show: String cr, x ].

Code with exception handlings:
|response|
[
response := (ZnClient new url: 'http://www.stroustrup.com/C++.html'; get; response).
response isSuccess
  ifFalse: [ Transcript show: 'Bad status : ', (response status asString) ]
  ifTrue:  [ response contents regex: '((http\://)?www([./#+-]\w*)+)' matchesDo:
           [ :x | Transcript show: String cr, x ]]
]
    on: NameLookupFailure do: [ Transcript show: 'Connection problem...' ].

If you try to check me out you will get an exception. Something like UTF8EncoderException: errorIllegalLeadingByte. The first thing I thought that the package pretty outdated. But then realized that it downloads other sites well. Then I thought it is not always well copes with utf8. In debug received byte = 150 (1001 0110) - it's bad if it is the first byte in sequence. I spent a some time on the localization error (moved up in call stack and found parsed line). So:

Lang.Next'14 Keynote: What � if anything � have we learned from C++? A 68 minute talk incl. Q&A.

You should see here squares or diamonds with question marks, depending on your browser. Trap from Stroustrup. At best, I had to write an exception handler in the package at the point where the line is created. But i just comment exception call and return ? character.

Also in code which calc the sequence length I return 1 in place of exception call (seems browsers does same).
P.S. some notes about Pharo (if anyone interested):

Too much GUI
Frendly for beginners.
Nice package searching
Nice highlighting and code autocompletion (not nice enough for serios IDE like IDEA but better than what I saw a few years ago in the same Pharo). Autocompletion sometimes trying deduce type - very thankless job.
Very chaotic GUI. At IDE we used to see tiled windows system, but there is only floating litle windows.
Where is imports, namespaces? There are many entities already. Is never a collision occurs?

Vimscript
function! Cpp()
    " grab the page in a new buffer in a new window in a new tab page
    tabedit http://www.stroustrup.com/C++.html

    " delete all lines that don't contain at least one 'http' hyperlink
    v/"http/d

    " only keep the hyperlink on every line
    %s/^.\+="\([^"]\+\)".\+$/\1
endfunction

JS/jQuery
$.get('http://www.stroustrup.com/C++.html',{},function(s){
    $(s).find('a').each(function() {
        console.log($(this).attr('href'))
    })
})

jQuery is a third-party library. You should use plain JavaScript.

@Athari if Mr. Stroustrup allows Boost for C++, jQuery should be fine for JS :P

This will only work if executed from the stroustrup domain since cross domain XHR requests need to be handled specifically by the server.

This answer has examples of jquey makings both easier and harder.  The XHR is drastically simpler, and getting the href attribute out of the dom object is needlessly more complicated.

@SethBattin Could you show us a simpler approach to getting the href attributes?

@JLRishe sure.  this.href

@SethBattin Oh, you just meant that one little bit. Well, I wouldn't call that needlessly more complicated. Sacrificing a few extra characters for consistency isn't the end of the world.

@JLRishe I'm not bothered by the few characters; it's still perfectly readable and short.  But it's also generating a complex jquery object to wrap around an already complex DOM object, and then accessing a property through a string lookup.  It could get there in one step rather than...lots of steps.  Consistency is great, but that kind of line makes me think it was applied by reflex.  Everything gets wrapped in $(...) all the time, whether it needs it or not, i.e.  jQuery because jQuery.  That's the aspect I don't like.

Python 2
I don't like using regex on HTML for established reasons, so here's an ungolfed HTMLParser approach:
from HTMLParser import HTMLParser
import urllib2 as u

class LinkFinder(HTMLParser):
    def handle_starttag(self, tag, attrs):
        if tag=='a':
            attrdct = dict(attrs)  # attrs is a list of ('key', 'value') tuples
            if 'href' in attrdct:
                href = attrdct['href']
                print href

url = "http://www.stroustrup.com/C++.html"
contents = u.urlopen(url).read()
LinkFinder().feed(contents)

Note this also gives local links such as index.html and anchors à la #learning. If you only want absolute links, prepend print href by
                if ':/' in href:  # also handles ftp, https etc.
                    print href

while for only omitting the anchors, use
                if !href.startswith('#'):
                    print href

Lua
Here's a lua solution complete with error checking and duplicate URL elimination like Stroustrups's C++ version.
Just made it in under 10 lines
local http, urlunique = require 'socket.http', {}

local body, resp, _, respmsg = http.request "http://www.stroustrup.com/C++.html"
assert(resp == 200, respmsg or resp)
for each in body:gmatch 'https?://[^%s<>"]+' do
  if not urlunique[each] then
    urlunique[each] = true
    print(each)
    end end

Here's another version using string.gsub fitting in just 6 lines!
local http, urlunique = require 'socket.http', {}

local body, resp, _, respmsg = http.request "http://www.stroustrup.com/C++.html"
assert(resp == 200, respmsg or resp)
body:gsub ('https?://[^%s<>"]+', function(r) urlunique[r] = true end)
for url in pairs(urlunique) do print(url) end

VBScript in Windows Script Host
That is, if this is stored in links.vbs file, run it via cscript /nologo links.vbs.
sub writeline( s ): WScript.StdOut.WriteLine s : end sub
function re( s ): set re = new RegExp: re.pattern = s: re.global = true: end function

set http = createobject( "Msxml2.XMLHTTP" )
http.open "GET", "http://www.stroustrup.com/C++.html", false: http.send
set links = re( "\w+://[^\""]+" ).execute( http.responseText )
for each link in links: writeline( link ): next

Addendum:
While the above lists all full links, which seems to be the goal, Stroustrup’s code additionally pares it down to unique links, and here’s a version that does that:
sub writeline( s ): WScript.StdOut.WriteLine s : end sub
function re( s ): set re = new RegExp: re.pattern = s: re.global = true: end function

set http = createobject( "Msxml2.XMLHTTP" )
http.open "GET", "http://www.stroustrup.com/C++.html", false: http.send
set links = re( "\w+://[^\""]+" ).execute( http.responseText )

set unique_links = createobject( "Scripting.Dictionary" )
on error resume next
for each link in links: unique_links.add ucase(link), link & "": next
for each link in unique_links.items(): writeline( link ): next

This reduces the number of output lines from 81 to 77.

Rust
Here is Rust solution:

extern crate reqwest;
extern crate select;
extern crate regex;

use select::document::Document;
use select::predicate::Name;
use regex::Regex;

fn main() {
    scrape_links("http://www.stroustrup.com/C++.html");
}

fn scrape_links(url: &str) {
    let resp = reqwest::get(url).unwrap();
    assert!(resp.status().is_success());
    let re = Regex::new(r"((http://)?www([./#\+-]\w*)+)").unwrap();
    Document::from_read(resp)
        .unwrap()
        .find(Name("a"))
        .filter_map(|n| n.attr("href"))
        .filter(|text| re.is_match(text))
        .for_each(|x| println!("{}", x));
}

R
I'm super new to regex so I gave this my best shot... any improvements appreciated!
grep("(http)s?://.*?", readLines("http://www.stroustrup.com/C++.html"), value = T)

readLines() just dumps the HTML source into a character vector. I then used grep() to find the URLs. The problem I ran into was that HTML element tags as well as corresponding link text were included in the output. substring() could be used to trim some of them I guess but it wouldn't work in all cases. If anyone knows a better way please let me know - especially if I could use a better regex.

regex is not only not mandatory, it is actually a rather bad method for parsing HTML. Anyway, your code is obviously much more concise than the C++ one :)

Python 2.7
Some readable Python code.
import urllib2
import re
page = urllib2.urlopen("http://www.stroustrup.com/C++.html").read()
for link in re.findall('"(http[s]?://.*?)"', page):
    print link

(C++)--
aka C
I'm suprised no one has done C yet.  The code is nice and clean.
linkfetch.c:
#include "inet_utils.h"
main(){
  char* SITE="www.stroustrup.com";
  char* PAGE="C++.html";
  char* REGX="((http://)?www([./#\\+-]\\w*)+)";
  int s = connect_to(SITE);
  FILE* f = fetch_page(s,SITE,PAGE);
  if (f) list_matches(f,REGX);
  else return printf("Can't fetch page %s/%s\n",SITE,PAGE);
  fclose(f); close(s);
}

That is, clean assuming you also write these simple utiliies:
inet_utils.h
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <netdb.h>
#include <regex.h>

#define SZ 1024 //good default buffer size
#define ERROR(s) (puts(s)&&0)
#define VP(e) ((void*)(long)(e))

inline int connect_to(char* w){
  //:returns socket connected to website w.
  struct sockaddr_in a;
  int s=socket(AF_INET, SOCK_STREAM, 0);                       // make socket
  struct hostent* h = gethostbyname(w);                        // lookup host
  if (!h) return ERROR("No Such Host");                        // check err
  a.sin_family=AF_INET;                                        // set ip address
  a.sin_port=htons(80);                                        // port 80
  memcpy(&a.sin_addr.s_addr, h->h_addr, h->h_length);          // of host
  if (connect(s,(struct sockaddr*)&a,sizeof(a))<0)             // connect
    return ERROR("can't connect");                             // handle error
  return s;                                                    // return socket
}

inline FILE* fetch_page(int s, char*w, char* p){
  //:returns open file handle for page p from site w connected to socket s

  FILE*f=fopen("/tmp/wcache","w+");                   // create cache file
  size_t n; char*b=malloc(SZ);                        // allocate temp buffer
  if (!s||!f||!b) return VP(ERROR("Resource Error")); // check for errors
  sprintf(b,                                          // compose request
          "GET / HTTP/1.0\r\nHost:%s\r\nAccept:*/*\r\nConnection:close\r\n\r\n",
          w);
  send(s,b,strlen(b),0);                         // send request
  while ((n=recv(s,b,SZ,0))>0)                   // receive response
    fwrite(b,1,n,f);                             // write it to cache file
  fseek(f,n=0,SEEK_SET);                         // read from beginnng
  fgets(b,SZ,f);                                 // look at first line
  if (!f||strncmp(strtok(b," "),"HTTP/",5))      // is it http?
    return VP(ERROR("Invalid Response"));        // error if not
  if (atoi(strtok(0," "))!=200)                  // check good status code
    return VP(ERROR("Bad Status Code"));         // error if not
  while (getline(&b,&n,f)>=0 && *b!='\r');       // skip headers upto blank line
  free(b);                                       // cleanup
  return f;                                      // return open handle
}

inline void list_matches(FILE* f, char* regx){
  //prints all strings from f which match regx
  regex_t r;
  size_t n = SZ; char*b=malloc(n);               // temp buffer
  if (regcomp(&r,regx,REG_NOSUB|REG_EXTENDED))   // compile regex
    puts("invalid regex");                       // handle error
  else while (getline(&b,&n,f)>0)                // fetch line
         if (!regexec(&r,b,0,0,0))               // check match
           puts(b);                              // show match
  regfree(&r); free(b);                          // cleanup
}

It compiles without warnings on out-of-the-box gcc (version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) )

Whether the code readable is highly questionble, considering weird formatting. Comments are nice, but how about properly formatting the code? You don't normally put multiple declarations with assignments, if and return on a single line, do you?

Clean and readable special purpose C usually comes by hiding ugly general purpose APIs and memory management details in "here be dragons"  wrapper functions.  I  could have prettified the 2nd part,  but it still wouldn't be nice. So I went for condensed instead.

This is ridiculous. Tell Linus about C code being unreadable by design. Properly formatted code is much easier to understand, there's nothing "magic" in your mess besides crazy formatting. http://pastebin.com/WHrqJzXb

Fine, here's some formatting. I didn't say C is unreadable by design, I said general purpose APIs are usually less readable than special purpose ones.  And I point to the gymnastics needed to populate the address for connecting to a web host as an example.

Swift (2.2)

What? Please write the Swift version. That square bracket nonsense is hurting my eyes :)

Mister Smith on the Objective-C answer.
let x = try!NSString(contentsOfURL:NSURL(string:"http://www.stroustrup.com/C++.html")!,encoding:4)
for y in try!NSRegularExpression(pattern:"\"((http)s?://.*?)\"",options:[]).matchesInString(x as String,options:[],range:NSMakeRange(0,x.length)){print(x.substringWithRange(y.range))}

Ungolfed:
let url = NSURL(string: "http://www.stroustrup.com/C++.html")!
let html = try! NSString(contentsOfURL: url, encoding: NSUTF8StringEncoding)
let regex = try! NSRegularExpression(pattern: "\"((http)s?://.*?)\"", options: [])
let results = regex.matchesInString(html as String, options: [], range: NSMakeRange(0, html.length))
for result in results {
    print(html.substringWithRange(result.range))
}

Assumes Foundation has been implicitly imported.
I can't access the original page for some reason, so this was tested with the Google Cached version: http://webcache.googleusercontent.com/search?q=cache:USk4BseSofcJ:www.stroustrup.com/C%2B%2B.html+&cd=1&hl=en&ct=clnk&gl=us
282 bytes.  Slightly shorter than the 292 byte Objective-C answer.  I'm falling back onto Foundation APIs, so there may be room for improvement by using pure Swift types.  The Cocoa APIs have also changed since the Objective-C answer was posted.
stringWithContentsOfURL: has been deprecated on NSString in favor of stringWithContentsOfURL:encoding:error:.  We lose some bytes on the encoding parameter, but gain some back because the ErrorPointer is no longer passed in with Swift.  The function now throws its NSError so instead, I'm using try! to force the execution of the NSString and NSRegularExpression initializers.  I also save some bytes by passing the raw value 4 as the value of the encoding parameter instead of the constant NSUTF8StringEncoding.  19 bytes saved.  But I lose some bytes by having to pass in an empty array ([]) instead of 0 to represent no options.  2 bytes lost there.  I also lose two bytes for every variable declaration since Swift requires whitespace characters on either side of the = character.
I lose 10 bytes by having to cast the NSString as a Swift String when calling matchesInString.  This is required because I'm using the NSString method contentsOfURL to get the web page HTML, but the NSRegularExpression method matchesInString takes in a Swift String as a parameter.  The implicit conversion between NSString and String isn't available here, so I am forced to use as to explicitly convert the types.
Interestingly enough matchesInString has not been completely converted to use Swift types.  It still requires its range parameter to be an NSRange struct instead of a Swift Range<String>.  I have to fall back and use NSMakeRange to create the range of the string.  I could save 4 bytes by using x.characters.indices of type Range<String.CharacterView.Index> instead, but Swift Range structs are not compatible with Foundation NSRange structs.  Additionally, if x were a Swift String, I might be able to save a few bytes by replacing substringWithRange with a subscript on String.  I haven't found a great way to do that yet, as creating two Index structs is currently longer than using substringWithRange.

Welcome to Programming Puzzles and Code Golf. Great answer, well explained, I'm not sure you need any help at all. Quick tip though: the convention on this site is to put your byte count in the title, just after the language name.

Oh, I've just noticed: This isn't a [tag:code-golf]: its objective is to "show Stroustrup what small and readable code is". If you could provide an ungolfed (readable) version, that would be very helpful.

@wizzwizz4 Thank you for your comments.  I didn't see the byte count next to the language name in the other answers, so I just added mine below.  I've also added an ungolfed version to my answer.

The reason you didn't see a byte count is because this is not a [tag:code-golf] challenge.

@wizzwizz4 Ah, got it.  Still learning.  Thank you!

Everybody is, even me. Even Dennis!

@wizzwizz4 also good to see that you're active on retrocomputing!  See you around.

ColdFusion
(using the same regex that Stroustrup uses)
<cfhttp url="http://www.stroustrup.com/C++.html" result="response" />
<cfif response.statusCode does not contain "200">
    <cfset writeOutput("Error getting the page: #response.statusCode#") />
<cfelse>
    <cftry>
        <cfset htmlLinks = REMatchNoCase("((http://)?www([./#\+-]w*)+)",response.fileContent) />
        <cfdump var="#htmlLinks#" />
    <cfcatch>
        <cfset writeOutput("There was a problem: #cfcatch.message# #cfcatch.detail#") />
    </cfcatch>
    </cftry>
</cfelse>

@Athari how do you do the code highlighting?

See Markdown help - Syntax highlighting for code. The syntax is usually <!-- language: lang-$LANGUAGE_NAME$ --> before the code block. If it doesn't work (support for many languages is missing), I look what CSS class is applied on StackOverflow to code blocks in questions for that language.

XQuery
HTML should be something similar to XML, so why not use langauges designed for this job?
If the page would've been "real" XHTML, we could run a query as beautiful as
doc("http://www.stroustrup.com/C++.html")//a/@href/data()

As this is crappy, broken HTML, let's use the BaseX-specific HTML parser (BaseX is an XQuery implementation):
html:parse(fetch:binary("http://www.stroustrup.com/C++.html"))//a/@href/data()

If limiting to URLs starting with http: is a must, lets do it:
html:parse(fetch:binary("http://www.stroustrup.com/C++.html"))//a/@href[starts-with(., 'http:')]/data()

Disclaimer: I am somewhat affiliated with the BaseX team as I wrote some code during my thesis. This would've been the tool of my choice for that kind of task, anyway. Other XQuery implementations provide similar HTML parsing capabilities, but I don't know their XQuery extensions by heart.

Bash + AWK
wget -q -O http://www.stroustrup.com/C++.html \
|awk '/((http:\/\/)?www([./#\+-]\w*)+)/ {print gensub(/.*((http:\/\/)?www([./#\+-]\w*)+).*/,"\\1","g")}'

I know it probably misses a few URLs, but I chosen to use the same regex than the original Stroustrup's code, so this should returns the same output than the original piece of code.
It may be possible to add some CR to make it more visible but I don't have a Linux available ATM for testing it works... (tested on Windows)
Here is a "clean" version of the AWK part:
/((http:\/\/)?www([./#\+-]\w*)+)/ {
    print gensub(/.*((http:\/\/)?www([./#\+-]\w*)+).*/,"\\1","g")
}

PHP 4.3+ / 5.0+
I know there are 2 different answers regarding PHP, but I'm going to show here a similar aproach, using nothing but standard functions.
For this, you will need to have the following on a file named php.ini ON THE SAME DIRECTORY:
allow_url_fopen= On
allow_url_include= On

THAT PART IS IMPORTANT!
In case you can't change (didn't worked with XAMPP), you have a default php.ini file on the PHP installation folder.
Changing the values will solve it.
Remember to restart apache after.
Since this isn't code-golf, I made my code somewhat readable.
Here it is:
ob_start(); //creates an output buffer

//now we 'include' the file, which will output the source code.
include 'http://www.stroustrup.com/C++.html';

$html = ob_get_clean(); //stores the output buffer and closes it

$offset = 0; //initial offset to search
$links = array(); //will contain all links

//while a link is found
while($pos = strpos($html, 'href="http', $offset))
{
    //look for the closing "
    $end = strpos($html, '"', $pos + 7);
    //take it from the string, store it into the array
    $links[] = substr($html, $pos + 6, ($end - $pos) - 6);
    //increase the offset, so it doesn't find the same link again
    $offset = $end + 1;
}

print_r($links); //spits it out, with the output buffer closed

I've added some comments to try to explain the code.
No regex used or DOM parsers: only pure hard-cold string manipulation.
For this to work in other pages, you must be sure that the values of the property href are between "", or it will fail.

F#
do
  use client = new System.Net.WebClient()
  let html = client.DownloadString "http://www.stroustrup.com/C++.html"
  System.Text.RegularExpressions.Regex.Matches(html, @"https?://[^""]+")
  |> Seq.cast<System.Text.RegularExpressions.Match>
  |> Seq.iter (printfn "%O")

CSS - idea
In Firefox, for example, for any page you are on, you can go to Tools | Web Developer | Style Editor, and use CSS to display anchors only:
* {display:none;}
a {display:block;}

However, the above will not work because display of parent elements overrides children.
Still working on a CSS solution, but suggestions welcome!

Maybe using positioning?  Push everything off the page to the left, then push links back on to the right?

@Izkata - looks like I've been scooped by Athari who provided a CSS solution!

You could use "* {font-size:0pt} a {font-size:8pt}" to display only the links, but you won't see the URLs

It seems Athari nailed it :)

C++/U++
Here is the U++ (which is 'another' C++ library, slightly different approach from boost) version:
#include <Core/Core.h>
#include <plugin/pcre/Pcre.h>

using namespace Upp;

CONSOLE_APP_MAIN
{
    String s = ToCharset(CHARSET_UTF8, HttpRequest("http://www.stroustrup.com/C++.html").Execute(),
                         CHARSET_ISO8859_1);
    RegExp x("href *= *\"(.*?)\"");
    while(x.GlobalMatch(s))
        Cout() << x.GetStrings()[0] << "\n";
}

(BTW, funny how most versions here are IMO not implementing the original specification: extract all links. There are many links on that page that do not start with http...)

Kudos, I just posted the same below (deleted now), and equally tried to reply to the original post ( BTW: http://www.ultimatepp.org/forums/index.php?t=msg&th=9167&start=0& ) but it won't let me to post links as a first message.

Lua
More concise, without checking for errors or unique URLs:
In readable...
http = require 'socket.http'
page = http.request 'http://www.stroustrup.com/C++.html'
page:gsub('http://www[%w./#\\+-]+', print)

...and less-readable...
require'socket.http'.request'http://www.stroustrup.com/C++.html':gsub('http://www[%w./#\\+-]+',print)

Javascript / DOM
var r = new XMLHttpRequest();
r.open('GET', 'http://www.stroustrup.com/C++.html', false);
r.send(null);
var div = document.createElement('div');
div.innerHTML = r.response;
[].slice.call(div.getElementsByTagName('a')).forEach( function(a) {
  if (a.href && a.getAttribute('href').charAt(0) != '#') console.log(a.href);
} );

(Tested in the Google Chrome javascript console.)
Of course, CORS blocks this by default - but its easy to disable CORS in Google Chrome for development purposes.

r.response is a string.  You have to set r.responseType = "document" first.  But then, you get an error because the request is synchronous.

Thanks @gilly3.  I've modified it to take the text response and put it in a div's innerHTML instead.  When running the browser with CORS disabled, this definitely now works.

Bash
 GET http://www.stroustrup.com/C++.html | grep -o "https\?://[^ \"]\+

needs libwww-perl and grep packages :)

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

authors: Bob Jarvis - Слава Україні


text:
Music: What's the name of this chord?
This is the reverse of Music: what's in this chord?, which is to print the notes in a given chord. This time the input is a list of notes in a chord, and your task is to output which chord it is.
Your program should support the following triadic chords. Examples are given with root C. Chords with other roots are the same chords with all notes rotated so C will become that root note, e.g. Dmaj consists of D, F# and A.
        C C#D D#E F F#G G#A A#B
          Db  Eb    Gb  Ab  Bb
Cmaj    C       E     G
Cm      C     D#      G
Caug    C       E       G#
Cdim    C     D#    F#
Csus4   C         F   G
Csus2   C   D         G

Note that Caug is the same as Eaug and G#aug, and Csus4 is the same as Fsus2. You can output either one but there is a bonus if you output them all.
And the seventh chords for the bonus are listed in the follow table:
        C C#D D#E F F#G G#A A#B
          Db  Eb    Gb  Ab  Bb
C7      C       E     G     A#
Cm7     C     D#      G     A#
Cmmaj7  C     D#      G       B
Cmaj7   C       E     G       B
Caug7   C       E       G#  A#
Cdim7   C     D#    F#    A

Rules

You can write either a complete program or a function.
The input is a list of notes, separated by a space or another convenient character. It can also be an array of strings (if it take input from function argument) or the string representation of such array.
Input doesn't have to be in specific order.
There may be duplicated notes in the input. They must be treated the same way as there is only one of them.
The output is the name of the chord. In case it will output multiple names, the same rule for input applies.
If the input isn't a supported chord, you should print the notes as-is. Your program can also support other chords not listed in the tables above (which is valid but has no bonus).
You can use other notations listed in the Wikipedia article. But if you choose C for C major, you should add a human readable prefix in either case to distinguish a chord with a single note.
You cannot use built-in functions for this task (if there is any).
This is code-golf. Shortest code in bytes wins.

Examples

Input: C D# G Output: Cm.
Input: C Eb G Output: Cm.
Input: C Eb F# Output: Cdim.
Input: F A C# Output: Faug, Aaug, C#aug, Dbaug or Faug Aaug C#aug, Faug Aaug Dbaug in any order.
Input: F D F F F F A A F Output: Dm.
Input: C D Output: C D.

Bonuses

-30 if it prints them all if there are more than one interpretations (for aug, sus4/sus2 and dim7).
-70 if it also supports seventh chords.
-200 if it accepts MIDI input and prints each chord it have received. Note that the notes doesn't have to begin or end at the same time. You decide what happens in the intermediate states (as long as it doesn't crash or stop working). You may assume there are no notes in percussion channels (or there is only one channel if that's convenient). It is recommended to also provide a text (or array) version for testing, especially if it is platform-dependent.

Can the input have flats or is it using sharp only? Should notes such as B# be handled?

@feersum It can have flats (unless you claim the -200 bonus). Added some examples. You don't need to handle B#, Cb, etc.

You say Csus4 is the same as Gsus2. I think you mean Csus2 is the same as Gsus4 don't you?

@Gareth ...Yes. Fixed.

Perl 5: 183 - 100 = 83
Edit: I managed to cut some extra characters so I also altered the chord names like in the Python solution, so I can pretend for a moment that I am leading.
#!perl -pa
for$z(0..11){$x=0;$x|=1<<((/#/-/b/+$z+1.61*ord)%12or$o=$_)for@F;$x-/\d+_?/-$_*4||push@r,$o.$'
for qw(36M 34- 68+ 18o 40sus2 33sus4 292_7 290-7 546-M7 548M7 324+7 146o7)}$_="@r
"if@r

Example:
$ perl chord.pl <<<"C D# G"
C-

Pyth 190 character - 30 - 70 = 90
=Q{cQdL+x"C D EF G A B"hb&tlbt%hx" #b"eb3FZQJx[188 212 199 213 200 224 2555 2411 2412 2556 2567 2398)u+*G12hHSm%-dyZ12mykQ0IhJ+Z@c"sus2 maj dim aug m sus4 7 m7 mmaj7 maj7 aug7 dim7"dJ=T0;ITQ

Not really happy with it. Used hard-coded chords.
Usage:
Try it here: Pyth Compiler/Executor. Disable debug mode and use "C D# G" as input.
Explanation:
First some preparation:
=Q{cQd
   cQd  split chord into notes "C D# G" -> ["C", "D#", "G"]
  {     set (eliminate duplicates)
=Q      Q = ...

Then a function that converts notes into integer
L+x"C D EF G A B"hb&tlbt%hx" #b"eb3
defines a function g(b),
  returns the sum of
     index of "D" in "C D EF G A B"
     and the index of "#" in " #b"
       (if b than use -1 instead of 2)

Then for each note, shift the coord and look it up in a table
FZQJx[188 ...)u+*G12hHSm%-dyZ12mykQ0IhJ+Z@c"sus2 ..."dJ=T0;ITQ
               implicit T=10
FZQ            for note Z in chord Q:
   mykQ         map each note of Q to it's integer value
   m%-dyZ12     shift it by the integer value of Z modulo 12
   S            sort it
   u+*G12hH 0   convert it to an integer in base 12
   x[188 ...)   look it up in the list (-1 if not in list)
   J            and store the value in J

   IhJ               if J>=0:
   +Z@c"sus2 ..."dJ   print the note Z and the chord in the list
=T0                   and set T=0
;            end loop
ITQ          if T:print chord (chord not in list)

Python 2, 335 bytes - 30 - 70 = 235
First attempt at a slightly longer golf, so I may be missing some obvious tricks.
def f(s,N="C D EF G A B",r=range,u=1):
 for i in r(12):
  for t in r(12):
   if(set((N.find(n[0])+" #".find(n[1:]))%12for n in s.split())==set(map(lambda n:(int(n,16)+i)%12,"0"+"47037048036057027047A37A37B47B48A369"[3*t:3*t+3]))):print(N[i],N[i+1]+"b")[N[i]==" "]+"M - + o sus4 sus2 7 -7 -M7 M7 +7 o7".split()[t];u=0
 if(u):print s

Comments:

I used alternative chord names from the Wiki page (see the end of the long line) to save space.
Chords are represented by 3 hex offsets each (0 is not required but included for triads to make them line up).
" #".find(n[1:]) works since " #".find("b") is -1 and " #".find("") is 0.

Sample output
>>> f("C D# G")
C-
>>> f("C Eb G")
C-
>>> f("C Eb F#")
Co
>>> f("F A C#")
Db+
F+
A+
>>> f("F D F F F F A A F")
D-
>>> f("C D")
C D
>>> f("C Eb Gb A")
Co7
Ebo7
Gbo7
Ao7

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

sort: votes


text:
Auto-meta-code-golf
You are sick of all of the codegolf challenges.  Hence you decide to write a program that will automatically golf some Python code for you.  There are 3 test cases:
print quickSort([0,7,3,-1,8,10,57,2])
def quickSort(arr):
    less = []
    pivotList = []
    more = []
    if len(arr) <= 1:
        return arr
    else:
        pivot = arr[0]
        for i in arr:
            if i < pivot:
                less.append(i)
            elif i > pivot:
                more.append(i)
            else:
                pivotList.append(i)
        less = quickSort(less)
        more = quickSort(more)
        return less + pivotList + more

for i in xrange(1, 101):
    if i % 15 == 0:
        print "FizzBuzz"
    elif i % 3 == 0:
        print "Fizz"
    elif i % 5 == 0:
        print "Buzz"
    else:
        print i

from sys import argv

def randomGenerator(seed=1):
    max_int32 = (1 << 31) - 1
    seed = seed & max_int32

    while True:
        seed = (seed * 214013 + 2531011) & max_int32
        yield seed >> 16

def deal(seed):
    nc = 52
    cards = range(nc - 1, -1, -1)
    rnd = randomGenerator(seed)
    for i, r in zip(range(nc), rnd):
        j = (nc - 1) - r % (nc - i)
        cards[i], cards[j] = cards[j], cards[i]
    return cards

def show(cards):
    l = ["A23456789TJQK"[c / 4] + "CDHS"[c % 4] for c in cards]
    for i in range(0, len(cards), 8):
        print " ", " ".join(l[i : i+8])

if __name__ == '__main__':
    seed = int(argv[1]) if len(argv) == 2 else 11982
    print "Hand", seed
    deck = deal(seed)
    show(deck)

Rules:

Your program must not target the code I posted specifically, and should work with any Python 2 code.  I reserve the right to change the source code being codegolfed.  You may assume that there are no multi-line strings (so you don't have build a full-blown parser), and that locals() is not called.
The output of your program should run in an identical manner as the original source code.  (Namely, it must produce the same output.  Variable names and language constructs can be changed, as long as the output remains the same)
You may use STDIO or a File to do your input/output of the source code.

Your score will be the sum of the bytes of your program's output.
(The code listed above has been taken from http://rosettacode.org/ under the GNU Free Documentation License 1.2)

Do we need to handle invalid code? IE if we make invalid code valid, is the entry valid?

This seems very similar to http://codegolf.stackexchange.com/questions/3652/write-a-code-golfer/26075

@Quincunx No, it should not deal with invalid code.  However, it should be able to handle any python code (including list comprehension and comments, even though it isn't in the programs above)

@KSab Yes, it is similar, but fundamentally different, as I have a scoring system.

@KSab I think that the two questions are different in both scoring and in task to be accomplished. This question: Shortest output wins. Old question: Most popular code that does five tasks plus "etc" wins. Who the heck knows what "etc" means.

Here's a bonus test case for people to try, to be devious.

What's your model for determining whether the output "[runs] in an identical manner as the original source code"? E.g. for the second example, I believe that removing if __name__ == '__main__': would affect the behaviour in some contexts but not others. For another example, if the ungolfed input assumes that it reads an int from stdin and throws one type of exception if given something else, could the golfed input throw a different type of exception if given a non-integer?

Removing if __name__ == '__main__': will change the behaviour.  Changing exception type will change the behaviour.  In the same context, the program should produce identical output (including STDERR).

Python 2, correct?

I'm a python noob, but for me it complains that the quickSort call is before the definition.  Works fine if I move the quickSort call to the end

@TheBestOne "[...] and should work with any Python 2 code."

This challenge does not seem good. I'll bet any answers that are posted (that attempt any sort of reduction) will fail on some code other than the single test case.

@feersum I updated the problem description.  There are no multi-line comments, meaning that most reductions will now work.

Even single-line strings are fairly tricky.

What about a program like this: random_long_variable=0;print locals()?

I didn't know about locals().  I'll exclude that as well, thanks.

Multiline strings aren't the only way to make empty lines functional

Python 2.7, 794
I have been meaning to build a minifier for Python for a while, so this is a good opportunity to investigate the problem.
The program uses a mix of regular expression analysis, and Python parser operations. White space is minimised. Variable that are defined by the user are replaced by a single letter variable (which is not in use!). Finally the while True statement is put on a diet.
The three test cases all verify as running correctly. I could imagine some pathological examples which could result in errors in the generated code but the algorithm should be robust under most circumstances.
Results
228 t1.py
128 t2.py
438 t3.py
794 total

Output
def c(a):
 b=[]
 d=[]
 f=[]
 if len(a)<=1:
  return a
 else:
  e=a[0]
  for i in a:
   if i<e:
    b.append(i)
   elif i>e:
    f.append(i)
   else:
    d.append(i)
  b=c(b)
  f=c(f)
  return b+d+f
print c([0,7,3,-1,8,10,57,2])

for i in xrange(1,101):
 if i%15==0:
  print"FizzBuzz"
 elif i%3==0:
  print"Fizz"
 elif i%5==0:
  print"Buzz"
 else:
  print i

from sys import argv
def a(k=1):
 b=(1<<31)-1
 k=k&b
 while 1:
  k=(k*214013+2531011)&b
  yield k>>16
def d(k):
 f=52
 h=range(f-1,-1,-1)
 g=a(k)
 for i,r in zip(range(f),g):
  j=(f-1)-r%(f-i)
  h[i],h[j]=h[j],h[i]
 return h
def m(h):
 l=["A23456789TJQK"[c/4]+"CDHS"[c%4]for c in h]
 for i in range(0,len(h),8):
  print" "," ".join(l[i:i+8])
if __name__=='__main__':
 k=int(argv[1])if len(argv)==2 else 11982
 print"Hand",k
 e=d(k)
 m(e)

Code
import sys
import re
from tokenize import generate_tokens
from token import tok_name
from keyword import iskeyword

wr = sys.stdout.write

def pyparse(text):
    'Return [TYPE,TOKEN] pair list'
    # Use KEYWORD,NAME,NUMBER,OP,STRING,NL,NEWLINE,COMMENT,INDENT,DEDENT
    rawtokens = generate_tokens(text.readline)
    tokens = [[tok_name[n], t] for n,t,p1,p2,dx in rawtokens]
    for tpair in tokens:
        if tpair[0] == 'NAME' and iskeyword(tpair[1]):
            tpair[0] = 'KEYWORD'
    return tokens

def finduservars(filename):
    'Return a set of user variables that we can replace with a-zA-Z'
    varset = set()
    for line in open(filename):
        line = line.strip()
        match = re.match(r'def\s+(\w+)\s*\((.*)\)\s*:', line)
        if match:
            func, args = match.groups()
            varset.add(func)
            arglist = re.findall(r'(\w+|=)', args)
            for a in arglist:
                if a == '=':
                    break  # keyword args follow - too hard to parse
                varset.add(a)
            continue
        match = re.match(r'(\w+)\s*=.+', line)
        if match:
            assigned = match.group(1)
            varset.add(assigned)
            continue
    return set(v for v in list(varset) if len(v) > 1)

filename = sys.argv[1]
tokenlist = pyparse(open(filename))

# Build map for var->char conversion:
varset = finduservars(filename)
singles = [text for tok,text in tokenlist if tok=='NAME' and len(text)==1]
allvar = [chr(n) for n in range(97,123)+range(65,91)]
charvar = [c for c in allvar if c not in singles]
varreplaced = list(varset)[:len(charvar)]
varmap = dict((v, charvar.pop(0)) for v in varreplaced)

prev = 'NONE'
indent = ['']
output = []
add = output.append
for tok, text in tokenlist:
    if tok == 'NL':
        continue
    elif tok == 'INDENT':
        indent.append( text.replace('    ', ' ') )
        output[-1] = indent[-1]
    elif tok == 'DEDENT':
        indent.pop(-1)
        output[-1] = indent[-1]
    elif tok == 'NEWLINE':
        add(text)
        add(indent[-1])
    elif tok in 'KEYWORD,NAME,NUMBER':
        if prev in 'KEYWORD,NAME,NUMBER':
            add(' ')
        if tok == 'NAME':
            if output[-2] == 'while' and text == 'True':
                add('1') # common verbose idiom
            else:
                add(varmap.get(text, text))
        else:
            add(text)
    else:
        add(text)
    prev = tok

wr(''.join(output))

sed, 1074 (down from 1390)
Very mild, low-hanging-fruit type of answer, to get the ball rolling:
/^$/d                  # Remove empty lines
/^[ <--TAB-->]*#/d     # Remove whole-line comments
s/    /<--TAB-->/g     # Replace 4 spaces with tabs
/^[^'"]*$/s/ *([|&:,<>=*/%+-]) */\1/g  # Remove spaces before/after operators

Replace <--TAB--> with real TAB characters
Obvious shortcoming:

Indents assumed to be exactly 4 spaces in input code.

Since we can assume no multi-line strings, then we only strip leading/trailing spaces from operators if there are no ' or " on the given line.  This could be improved, but <mumbles something about sed regex always being greedy>.
Test as follows:
$ cat qs.py fizzbuzz.py cards.py | wc -c
1390
$ sed -rf pygolf.sed qs.py fizzbuzz.py cards.py | wc -c
1074
$ sed -rf pygolf.sed qs.py fizzbuzz.py cards.py | python
[-1, 0, 2, 3, 7, 8, 10, 57]
1
2
Fizz
...
98
Fizz
Buzz
Hand 11982
  AH AS 4H AC 2D 6S TS JS
  3D 3H QS QC 8S 7H AD KS
  KD 6H 5S 4D 9H JH 9S 3C
  JC 5D 5C 8C 9D TD KH 7C
  6C 2C TH QH 6D TC 4S 7S
  JD 7D 8H 9C 2H QD 4C 5H
  KC 8D 2S 3S
$

You don't need to check for multi-line strings, but your last two definitely need to be updated.

@NathanMerrill yup.  The operator leading/trailing space one is a bit better now, but the indent one will be much harder to generalize - and is where I get about 2/3 of the gain.

Python 3.4, 1134
This program should work alright for most programs. Strangely, Sp3000 test case is much easier to optimize for my program than your programs. Input is accepted through the file specified in the first argument. The actual file is modified.
import subprocess
from sys import argv

progamtext = open(argv[1]).read()

if 'argv' in progamtext or 'input' in progamtext or 'open' in programtext:#Make sure the program always produces the same results.
    exit(0)

program = subprocess.Popen(['C:\Python27\python', argv[1]], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
program.wait()
erroroutput1 = str(program.stderr.read())
output1 = str(program.stdout.read())
program = subprocess.Popen(['C:\Python27\python', argv[1]], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
program.wait()
erroroutput2 = str(program.stderr.read())
output2 = str(program.stdout.read())
if erroroutput1 != erroroutput2 or output1 != output2:#Make sure the program always produces the same results.
    exit(0)

newprog = ''
if erroroutput1:
    newprog += "import sys\n" + "sys.stderr.write("+ erroroutput1 + ')'
    if output1:
        newprog += "\n"
if output1:
    newprog += 'print ' + output1

if len(newprog) > len(progamtext):
    exit(0)

open(argv[1],mode='w').write(newprog)

How it works:
First, this program checks to see if your program interacts with the user at all or uses random. If it does, the program is unmodified.
Next, the program is ran. The program is then replaced with print "output". Finally, if the program is shorter than its output, it is unmodified.
Sp3000's program, optimized:
import sys
sys.stderr.write(b'')
print b'0.540377721372\r\n3\r\n1\r\n7\r\n99\r\nf\r\n[5, 5]\r\n53\r\n53\r\n53\r\n'

Sp3000's super bonus program, optimized:
The optimized version is only off .001% of the time.
import sys
sys.stderr.write(b'')
print b'B\r\n'

I'm sure there are other external effects than argv, input and random, which your code would break. ;)

Hah. Maybe I should have put in some non-determinism - print id(0) is a good one.

@Martin Fixed (mostly). :)

Here's a super bonus test case, just for you.

Heh, very creative.

Maybe if the program is shorter than its output, you should work on optimizing whitespace, replacing vars with single-char names, etc.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/