[Question]
  [
Write a program that connects to this site, downloads the very answer in which it is posted, extracts its own source code and prints it out. The output must be identical to the source code. Shortest code (in bytes) wins.
Rules:
* No URL shorteners allowed.
* The answer must have a regular format - a heading with the language name and size, optional description, code block, optional description and explanation. No unnatural delimiters allowed.
* The output must originate from the actual code block posted on the site.
* The functionality must not depend on the position in the answer list; it should work even if there are multiple pages and the answer it not on the first one.
* **New:** special note for answers that are supposed to be run in a browser: it is ok to require running them on the codegolf domain (to obey the same-origin policy) but the domain and path should be included in the solution in order to make it fair.
  
[Answer]
# Bash + coreutils + Lynx browser, 61 bytes
Thanks to @FDinoff for the tips:
```
lynx -dump codegolf.stackexchange.com/posts/28164/body|grep 2
```
[Answer]
# Ruby, ~~155~~ ~~186~~ ~~195~~ ~~148~~ ~~138~~ ~~110~~ 97 characters
```
require'open-uri';puts open('http://codegolf.stackexchange.com/posts/28159/body').read[/req.+;/];
```
I had to make it one line, because otherwise it would output newlines as `\n` instead of actual newlines.
* ~~+31 characters because I didn't notice some characters were being escaped.~~
* ~~+9 characters to get rid of the annoying backslash.~~
* Thanks to Nathan Osman for saving 2 chars, and Ventero for saving 55 (!!!) by removing the need for most of the fixes listed above.
---
## The explanation
Let's beautify this a bit first. However, I'm going to have to use a somewhat... interesting notation in this code. I can't use semicolons at all in this post, for reasons explained later, so I will use `{SEMI}` in place of semicolons instead.
```
require 'open-uri'
resp = open('http://codegolf.stackexchange.com/posts/28159/body').read
puts resp.match(/req.+{SEMI}/){SEMI}
```
Alright, now let's walk through this. The first two lines are fairly self-explanatory -- they fetch the HTML text of this answer.
Now, the last line is the interesting one here. You see that seemingly useless semicolon at the end of the code? It's absolutely required, and here's why.
First, `resp.match` extracts the code to be printed. The regexp it uses for this is the trick: `/req.+{SEMI}/`. It grabs the start of the code, `REQuire'net/http'`, by searching for `req` (`re` would grab my `REputation`). Then, it finds the end of the code by searching for a semicolon! Since `+` is greedy by default, it will keep going until it finds the semicolon that signifies the end of the code. See why I can't use semicolons anymore?
~~After that, I don't have to unescape anything thanks to Ventero's fix of not using `\` at all anymore. All I have to do is fix `{AMPERSAND}` changing into `{AMPERSAND}amp{SEMI}`, which can be achieved simply by removing the `amp{SEMI}` part.~~ No need for this anymore because of new URL. After that, the original code has been retrieved! *(Note: I can't use the ampersand either, because that gets HTML-encoded which causes a semicolon to be created.)*
[Answer]
## PowerShell - 69 62
```
(irm codegolf.stackexchange.com/posts/28236/body).div.pre.code
```
[Answer]
# JavaScript - 123 122 101 95 92 91 87 86 114
```
with(new XMLHttpRequest)send(open(0,/\codegolf.stackexchange.com\posts\28175\body/,0)),alert(/w.*/.exec(response))
```
Runs in the console of your web browser on this page. Tested on the latest Chrome and Firefox.
*edit: +28 bytes to add the full domain.*
*Firefox doesn't like my Regex URL trick anymore with this update :(*
Here's the rule-breaking 86 byte solution:
```
with(new XMLHttpRequest)send(open(0,/posts\28175\body/,0)),alert(/w.*/.exec(response))
```
[Answer]
# Ruby + wget + gunzip, 159 86 82 71
Using tip of @FDinoff to use `http://codegolf.stackexchange.com/posts/28173/body`.
```
puts `wget -qO- codegolf.stackexchange.com/posts/28173/body`[/pu.*\]/]
```
Tested. Thanks to @ace and @Bob for command line optimization.
[Answer]
# CJam - 53
```
"codegolf.stackexchange.com/posts/28184/body"g54/1=);
```
I'm making this community wiki since I'm answering my own question and don't really want to compete :p  
Credits to FDinoff for the URL choice.
[Answer]
# Rebmu, 91 characters
Due to the Catch-22 I have to post to get this answer's URL. :-/ Okay, got it.
```
paTSrd http://codegolf.stackexchange.com/a/28154[th<a name="28154">th<code>cpCto</code>]prC
```
Rebmu is a dialect of Rebol, and [you can read all 'bout it](https://github.com/hostilefork/rebmu). The equivalent Rebol here would be:
```
parse to-string read http://codegolf.stackexchange.com/a/28154 [
    thru <a name="28154">
    thru <code>
    copy c to </code>
]
print c
```
Rebol's PARSE is a sort of highly-literate answer to RegEx. It starts a parser position of the input *(which can be any series, including structural blocks...binary data...or string types)*. The rules are a language for how the parse position moves.
Tags and URLs are really just strings under the hood in the language. But they are "flavored", and as Rebol is dynamically typed you can check that type. READ for instance knows that if you give it a URL-flavored string, then it should dispatch to a scheme handler to do the reading. (In this case, the one registered for HTTP). You get back UTF-8 bytes by default, so we use to-string to decode that and get a series of codepoints in a normal Unicode string.
In the case of the parse dialect, encountering a tag type is just matched as if it were a string that looked like the tag. THRU is an instruction meaning "skip until the ensuing rule is matched, and then place the match position at the end of what you just matched." (TO is the analogue that matches, but leaves the parse position before the element).
So we zip along past the `<a name="28154">`. Then we zip past the next occurrence of `<code>`, with our parse position now located right after the `>`. PARSE's COPY command then lets us copy data up to another rule, in this case that rule is `[TO </code>]`... so we get into the variable C everything up until right before that `<`.
[Cool](http://blog.hostilefork.com/why-rebol-red-parse-cool/), huh? :-)
Technically I could shave more off it, for instance by seeking `TO "</"` and that saves three characters--there's no need to match the whole `</code>` end tag when just `</` would do. Similar arguments could me made for the start tag. But Rebmu is about *literate* golfing...even if you might think it looks odd at first!
**UPDATE**: the `/body` trick is out of the bag, but I'm similarly going to leave it as-is...because I think it is more educational this way.
[Answer]
## Java now 634, 852, was 1004
Code has been updated; thanks for suggestions.
Golfed: now replaces &gt with >
```
//bacchus
package golf;
import java.net.*;
import java.util.*;
public class G{
public static void main(String[] a) throws Exception {
Scanner z;
URL u;
int x=0;
String s;
u=new URL("http://codegolf.stackexchange.com/questions/28154/write-a-program-that-downloads-itself");
z=new Scanner(u.openConnection().getInputStream());
z.useDelimiter("\\s*//bacchus\\s*");
while(z.hasNext())
{
s=z.next();
s=s.replace("&gt;", ">");
if(x>0)System.out.println("//bacchus\n"+s);
x++;
if(x>2)break;
}
System.out.println("//bacchus\n");
}
}
//bacchus
```
Submitting for testing, I will edit and try golfing it shortly.
Needed to change x>1 to x>2 because test string is also in my code.
Note: Code golf replaces > symbol to &gt.
```
//bacchus
package golf;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
public class Golf {
    public static void main(String[] args) throws IOException {
        URL u;
        URLConnection c;
        InputStream i;
        InputStreamReader r;
        BufferedReader b;
        String s;
        int x=0;
        try {
            u=new URL("http://codegolf.stackexchange.com/questions/28154/write-a-program-that-downloads-itself");
            c=u.openConnection();
            i=c.getInputStream();
            r=new InputStreamReader(i);
            b=new BufferedReader(r);
            while((s=b.readLine())!=null)
            {
                if(s.contains("//bacchus")) x++;
                if(x>0)System.out.println(s);
                if(x>2) break;
            }
            i.close();
            b.close();
        } catch (MalformedURLException ex) {
        }
    }
}
//bacchus
```
[Answer]
# Python, 175 167 bytes
This uses two external libraries; I didn't read that it was unauthorized.
```
import bs4,requests
print(bs4.BeautifulSoup(requests.get('http://codegolf.stackexchange.com/q/28154').text).select('#answer-28171')[0].select('pre > code')[0].string)
```
Longer, but nicer looking code:
```
import bs4, requests
request = requests.get('http://codegolf.stackexchange.com/q/28154')
soup = bs4.BeautifulSoup(request.text)
answer = soup.select('#answer-28171')[0]
code = answer.select('pre > code')[1].string
print(code)
```
[Answer]
## w3m 45 characters
```
w3m codegolf.stackexchange.com/a/28336|grep ‚òª
```
[Answer]
## JavaScript, 228
```
r=new XMLHttpRequest()
c='code'
r.open('GET','//'+c+'golf.stackexchange.com/posts/28157/body')
r.onreadystatechange=function(){this.readyState==4&&alert((a=r.responseText).substr(i=a.indexOf(c)+5,a.indexOf('/'+c)-i-1))}
r.send()
```
Runs on this page.
[Answer]
## Haskell, 563 613 bytes
```
import Control.Monad
import Data.List
import Network.HTTP
m%f=join(fmap f m)
q s=(simpleHTTP(getRequest"http://codegolf.stackexchange.com/questions/28154/write-a-program-that-downloads-itself?answertab=oldest#tab-top"))%getResponseBody%(putStrLn.head.filter((==)(s++show s)).map(take 613).tails)
main=q"import Control.Monad\nimport Data.List\nimport Network.HTTP\nm%f=join(fmap f m)\nq s=(simpleHTTP(getRequest\"http://codegolf.stackexchange.com/questions/28154/write-a-program-that-downloads-itself?answertab=oldest#tab-top\"))%getResponseBody%(putStrLn.head.filter((==)(s++show s)).map(take 613).tails)\nmain=q"
```
Tested. Has page support via "oldest posts" feature. Uses quine-line structure to find what to print.
The `import Control.Monad` is only because `>>=` generates `&gt;` in HTML.
[Answer]
#  Javascript +jQuery, 87, 67
I'm not sure wether I'm allowed to use jQuery, but: 
```
$('body').load('//codegolf.stackexchange.com/posts/28268/body pre')
```
---
### Javascript + jQuery, if excecuted in this page: 27, 25
For fun, if it would be excecuted here:
```
$('[id$=268] pre').html()
```
`$('[id$=28268] pre').html()`
[Answer]
# Dart, 164
I thought I'd try this in Dart, is pretty fun to use imo.
This can be run in the console in DartEditor, but does require the http package added in pubspec.yaml
```
import"package:http/http.dart"as h;h.read("http://codegolf.stackexchange.com/posts/28215/body").then((s){print(new RegExp(r"im.+(?:})").firstMatch(s).group(0));});}
```
Ungolfed version:
```
import "package:http/http.dart" as h;
void main()
{
  h.read("http://codegolf.stackexchange.com/posts/28215/body").then((s)
  {
    print(new RegExp(r"im.+(?:})").firstMatch(s).group(0));
  });
}
```
[Answer]
## R 114 characters
```
library(XML);cat(xpathSApply(xmlParse("http://codegolf.stackexchange.com/posts/28216/body"),'//code',xmlValue)[1])
```
No real magic here: it takes the value of the field between the html tags `<code></code>`. Uses library `XML` (as one can see in the code quite obviously). Outputs the result as stdout.
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), 108 bytes
```
6 3‚å∑‚éïXML{(‚éïSE.SALT.New'HttpCommand'('GET'‚çµ)).Run.Data}'https://codegolf.stackexchange.com/posts/211205/body'
```
[Don't Try it online, try it locally](https://tio.run/##SyzI0U2pTMzJT///30zB@FHP9kd9UyN8fao1gHSwq16wo0@Inl9qubpHSUmBc35ubmJeirqGurtriPqj3q2amnpBpXl6LoklibXqGUAVxVb6@sn5Kanp@TlpesUlicnZqRXJGYl56al6yfm5@gX5xSXF@kaGhkYGpvpJ@SmV6v//AwA "APL (Dyalog Unicode) ‚Äì Try It Online")
~~Correct link coming soon.~~
## Output:
[![enter image description here](https://i.stack.imgur.com/Bp2Ih.png)](https://i.stack.imgur.com/Bp2Ih.png)
[Answer]
# Java, ~~300~~ 294
```
import java.net.*;import java.util.*;public class G{public static void main (String [] a) throws Exception{Scanner s=new Scanner(new URL("http://codegolf.stackexchange.com/posts/28189/body").openConnection().getInputStream()).useDelimiter("./?[c]ode\\W");s.next();System.out.print(s.next());}}
```
An improved version of bacchusbeale's answer which:
* doesn't close resources unnecessarily
* doesn't declare unnecessary variables
* uses a `Scanner` to avoid having to loop over the input
* uses a regexp that doesn't match itself to avoid having to skip over a middle occurrence of the start/end marker.
Updated:
* Use a direct URL to the post, so we don't need a unique comment to identify the start/end of the code; now uses `<code>[...]</code>` as the delimiters to search for (actually using the regular expression "./?[c]ode\W", so as to avoid having to decode `&lt;` and `&gt;` -- the "\W" is necessary rather than the shorter "." to avoid it matching part of the URL to the post, unfortunately, which costs 2 characters, and the square brackets around c prevent the regex matching itself).
[Answer]
# w3m 55 bytes
```
w3m codegolf.stackexchange.com/posts/28242/body|grep x
```
Based on @DigitalTrauma
[Answer]
# Ruby, ~~237~~ ~~215~~ ~~146~~ 132
```
require'mechanize'
a=Mechanize.new
puts a.get('http://codegolf.stackexchange.com/a/28159').search('.lang-rb code:nth-child(1)').text
```
[Answer]
# Processing, 90
```
print(loadStrings("http://codegolf.stackexchange.com/posts/28657/body")[2].substring(11));
```
**Edit:** Finally got it!
[Answer]
# Python, 164
Works by extracting the text between the code tags. It is quite long but it will always function correctly unless the html page is edited directly or a new code block is added before the one below (having a block of code after should have no effect on the output of the program).
```
import urllib2
print urllib2.urlopen("http://codegolf.stackexchange.com/posts/28617/body").read().split(chr(60)+"code"+chr(62))[1].split(chr(60)+"/code"+chr(62))[0]
```
[Answer]
# bash + awk, 71 bytes
```
curl -sL codegolf.stackexchange.com/q/28154 |awk -F\> '/\#/ {print $3}'
```
[Answer]
# Javascript, 138
```
a=window.open("http://codegolf.stackexchange.com/posts/28160/body");setTimeout('alert(a.document.body.innerHTML.match(/a=.*9\\)/)[0])',99)
```
This works assuming that the page loads in under 99 ms. It also has to be run via a console opened on a codegolf.SE page, because of the same origin policy.
[Answer]
## Perl 5.10, 155 127 122 117 bytes
```
use XML::LibXML;say XML::LibXML->new->parse_file('http://codegolf.stackexchange.com/posts/28330/body')->find('//pre')
```
Using `XML::LibXML`.
[Answer]
## Shell and xmllint, 82 bytes
```
xmllint --xpath 'string(//pre)' http://codegolf.stackexchange.com/posts/28333/body
```
]