arrogant 0.3.0

Fully conformant HTML5 dom library with CSS4 selectors.


To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:

arrogant

Fully conformant HTML5 dom library with CSS4 selectors. Based on Modest.

Tested on Linux. Should work fine on OSX. Never tried on Windows.

prerequisites: how to build & install modest

Modest is written in pure C, without any external dependency. Just fetch source code and compile.

git clone https://github.com/2night/arrogant.git
cd arrogant
git submodule update --init
cd c/Modest
make
sudo make install
sudo ldconfig

run an example

dub -c arrogant_test_app

hello world

import arrogant;
import std.stdio : writeln, stdout;

void main()
{
   auto src = `<html><head></head><body><div>Hello World</div></body></html>`;
   auto arrogant = Arrogant();
   auto tree = arrogant.parse(src);

   // Change div content from "Hello World!" to "Hello D!"
   tree.byTagName("div").front.innerText = "Hello D!";

   // Print the edited html
   writeln(tree.document);

   assert(tree.document.innerHTML == "<html><head></head><body><div>Hello D!</div></body></html>");
}

get data from webpage

import arrogant;
import std.net.curl;
import std.stdio : writeln, stdout;

void main()
{
   auto src = "https://forum.dlang.org".get;
   auto arrogant = Arrogant();
   auto tree = arrogant.parse(src);
   size_t cnt = 0;

   writeln("Recent posts on forum.dlang.org:\n");
   
   // Search for summary divs
   foreach(post; tree.byClass("forum-index-col-lastpost"))
   {
      string title = post.byClass("forum-postsummary-subject").front["title"];
      string author = post.byClass("forum-postsummary-author").front["title"];
      string date = post.byCssSelector("span.forum-postsummary-time > span").front["title"];

      writeln("Title: ", title);
      writeln("By: ", author);
      writeln("Date: ", date);
      writeln("--------------");

      cnt++;
   }

   writeln("Total: ", cnt, " posts");
 }

more

Check this code or read documentation

Authors:
  • Andrea Fontana
Dependencies:
none
Versions:
0.3.0 2019-Feb-21
0.2.0 2018-Jun-18
0.1.0 2018-Jun-13
~master 2020-Sep-17
Show all 4 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 0 downloads this month

  • 906 downloads total

Score:
1.4
Short URL:
arrogant.dub.pm