Skip to content
This repository was archived by the owner on Feb 4, 2023. It is now read-only.

Commit c00b7bf

Browse files
committed
improved quickstart
1 parent b25db0e commit c00b7bf

File tree

1 file changed

+43
-2
lines changed

1 file changed

+43
-2
lines changed

quickstart.rst

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,49 @@ Once CasperJS is :doc:`properly installed <installation>`, you can write your fi
1212

1313
.. _quickstart_javascript:
1414

15-
Let's scrape Google!
16-
--------------------
15+
A minimal scraping script
16+
-------------------------
17+
18+
Fire up your favorite editor, create and save a ``sample.js`` file like below::
19+
20+
var casper = require('casper').create();
21+
22+
casper.start('http://casperjs.org/', function() {
23+
this.echo(this.getTitle());
24+
});
25+
26+
casper.thenOpen('http://phantomjs.org', function() {
27+
this.echo(this.getTitle());
28+
});
29+
30+
casper.run();
31+
32+
Run it:
33+
34+
.. code-block:: text
35+
36+
$ casperjs sample.js
37+
38+
You should get something like this:
39+
40+
.. code-block:: text
41+
42+
$ casperjs c.js
43+
CasperJS, a navigation scripting and testing utility for PhantomJS | CasperJS 1.0.0
44+
PhantomJS: Headless WebKit with JavaScript API
45+
46+
.. topic:: What did we just do?
47+
48+
1. we created a new :ref:`Casper <casper_module>` instance
49+
2. we started it and opened ``http://casperjs.org/``
50+
3. *once* the page has been loaded, we asked to print the title of that webpage (the content of its ``<title>`` tag)
51+
4. *then* we opened another url, ``http://phantomjs.org/``
52+
5. *once* the new page has been loaded, we asked to print its title too
53+
6. we executed the whole process
54+
55+
56+
Now let's scrape Google!
57+
------------------------
1758

1859
In the following example, we'll query google for two terms consecutively, *"casperjs"* and *"phantomjs"*, aggregate the result links in a standard ``Array`` and output the result to the console.
1960

0 commit comments

Comments
 (0)