浏览代码

first pass

jmelesky 7 年之前
父节点
当前提交
a9ed2e6599
共有 1 个文件被更改,包括 35 次插入1 次删除
  1. 35 1
      src/main.rs

+ 35 - 1
src/main.rs

@@ -1,3 +1,37 @@
+extern crate reqwest;
+extern crate select;
+
+use select::document::Document;
+use select::predicate::Name;
+
+
 fn main() {
-    println!("Hello, world!");
+    scrape_feats("http://www.archivesofnethys.com/Feats.aspx?Category=Combat");
 }
+
+fn scrape_feats(url: &str) {
+
+    let resp = reqwest::get(url).unwrap();
+    assert!(resp.status().is_success());
+
+    let doc = Document::from_read(resp).unwrap();
+
+    let mut header = true;
+    for node in doc.find(Name("tr")) {
+        // skip the first one
+        if header {
+            header = false;
+        } else {
+            let name = node.find(Name("td")).next().unwrap().text();
+            let prereqs = node.find(Name("td")).next().unwrap().text();
+            let benefit = node.find(Name("td")).next().unwrap().text();
+
+            println!("|{}|{}|{}|\n", name, prereqs, benefit);
+        }
+    }
+
+
+}
+
+
+