For those ready to take the challenge

Adam D. Ruppe via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jan 9 09:15:42 PST 2015


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.


More information about the Digitalmars-d-learn mailing list