Thread overview | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
January 09, 2015 Re: For those ready to take the challenge | ||||
---|---|---|---|---|
| ||||
Posted in reply to eles | On Fri, 09 Jan 2015 13:50:28 +0000, eles wrote: > https://codegolf.stackexchange.com/questions/44278/debunking- stroustrups-debunking-of-the-myth-c-is-for-large-complicated-pro Was excited to give it a try, then remembered...std.xml :( |
January 09, 2015 Re: For those ready to take the challenge | ||||
---|---|---|---|---|
| ||||
Posted in reply to Justin Whear | On Friday, 9 January 2015 at 16:55:30 UTC, Justin Whear wrote: > Was excited to give it a try, then remembered...std.xml :( Well, as the author of my dom.d, I think it counts as a first party library when I use it! --- import arsd.dom; import std.net.curl; import std.stdio, std.algorithm; void main() { auto document = new Document(cast(string) get("http://www.stroustrup.com/C++.html")); writeln(document.querySelectorAll("a[href]").map!(a=>a.href)); } --- prints: [snip ... "http://www.morganstanley.com/", "http://www.cs.columbia.edu/", "http://www.cse.tamu.edu", "index.html", "C++.html", "bs_faq.html", "bs_faq2.html", "C++11FAQ.html", "papers.html", "4th.html", "Tour.html", "programming.html", "dne.html", "bio.html", "interviews.html", "applications.html", "glossary.html", "compilers.html"] Or perhaps better yet: import arsd.dom; import std.net.curl; import std.stdio; void main() { auto document = new Document(cast(string) get("http://www.stroustrup.com/C++.html")); foreach(a; document.querySelectorAll("a[href]")) writeln(a.href); } Which puts each one on a separate line. |
January 09, 2015 Re: For those ready to take the challenge | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | Huh, looking at the answers on the website, they're mostly using regular expressions. Weaksauce. And wrong - they don't find ALL the links, they find the absolute HTTP urls! |
January 09, 2015 Re: For those ready to take the challenge | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | On Fri, 09 Jan 2015 17:18:42 +0000, Adam D. Ruppe wrote: > Huh, looking at the answers on the website, they're mostly using regular expressions. Weaksauce. And wrong - they don't find ALL the links, they find the absolute HTTP urls! Yes, I noticed that. `<script src="http://app.js"`></script>` isn't a "hyperlink". Wake up sheeple! |
January 10, 2015 Re: For those ready to take the challenge | ||||
---|---|---|---|---|
| ||||
Posted in reply to eles | On Friday, 9 January 2015 at 13:50:29 UTC, eles wrote: > https://codegolf.stackexchange.com/questions/44278/debunking-stroustrups-debunking-of-the-myth-c-is-for-large-complicated-pro Link to answer in D: http://codegolf.stackexchange.com/a/44417/13362 |
January 10, 2015 Re: For those ready to take the challenge | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jesse Phillips | On 1/9/15 6:10 PM, Jesse Phillips wrote:
> On Friday, 9 January 2015 at 13:50:29 UTC, eles wrote:
>> https://codegolf.stackexchange.com/questions/44278/debunking-stroustrups-debunking-of-the-myth-c-is-for-large-complicated-pro
>>
>
> Link to answer in D:
> http://codegolf.stackexchange.com/a/44417/13362
Nailed it. -- Andrei
|
January 10, 2015 Re: For those ready to take the challenge | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jesse Phillips | On Saturday, 10 January 2015 at 02:10:04 UTC, Jesse Phillips wrote: > On Friday, 9 January 2015 at 13:50:29 UTC, eles wrote: >> https://codegolf.stackexchange.com/questions/44278/debunking-stroustrups-debunking-of-the-myth-c-is-for-large-complicated-pro > > Link to answer in D: > http://codegolf.stackexchange.com/a/44417/13362 I think byLine is not necessary. By default . will not match line breaks. One statement solution: import std.net.curl, std.stdio; import std.algorithm, std.regex; void main() { get("http://www.stroustrup.com/C++.html") .matchAll(`<a.*?href="(.*)"`) .map!(m => m[1]) .each!writeln(); } Requires Phobos PR#2024 ;) |
January 10, 2015 Re: For those ready to take the challenge | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | On Friday, 9 January 2015 at 17:18:43 UTC, Adam D. Ruppe wrote:
> Huh, looking at the answers on the website, they're mostly using regular expressions. Weaksauce. And wrong - they don't find ALL the links, they find the absolute HTTP urls!
Yeah... Surprising, since languages like python includes a HTML parser in the standard library.
Besides, if you want all resource links you have to do a lot better, since the following attributes can contain resource addresses: href, src, data, cite, xlink:href…
You also need to do entity expansion since the links can contain html entities like "&".
Depressing.
|
January 10, 2015 Re: For those ready to take the challenge | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | On Friday, 9 January 2015 at 17:18:43 UTC, Adam D. Ruppe wrote:
> Huh, looking at the answers on the website, they're mostly using regular expressions. Weaksauce. And wrong - they don't find ALL the links, they find the absolute HTTP urls!
Since it is a comparison of languages it's okay to match the original behaviour.
|
Copyright © 1999-2021 by the D Language Foundation