mirror of https://github.com/vitalif/phantomjs
Merge branch 'master' into 1.7
commit
f4221ea1de
|
@ -1,8 +1,8 @@
|
||||||
# [PhantomJS](http://phantomjs.org) - Scriptable Headless WebKit
|
# [PhantomJS](http://phantomjs.org) - Scriptable Headless WebKit
|
||||||
|
|
||||||
PhantomJS ([www.phantomjs.org](http://phantomjs.org)) is a headless WebKit scriptable with JavaScript or CoffeeScript. It is used by hundreds of [developers](http://code.google.com/p/phantomjs/wiki/ExternalArticles) and dozens of [organizations](http://code.google.com/p/phantomjs/wiki/WhoUsesPhantomJS) for web-related development workflow.
|
PhantomJS ([www.phantomjs.org](http://phantomjs.org)) is a headless WebKit scriptable with JavaScript or CoffeeScript. It is used by hundreds of [developers](https://github.com/ariya/phantomjs/wiki/Buzz) and dozens of [organizations](https://github.com/ariya/phantomjs/wiki/Users) for web-related development workflow.
|
||||||
|
|
||||||
The latest [stable release](http://code.google.com/p/phantomjs/wiki/ReleaseNotes) is version 1.6 (codenamed "Lavender"). Follow the official Twitter stream [@PhantomJS](http://twitter.com/PhantomJS) to get the frequent development updates.
|
The latest [stable release](http://phantomjs.org/release-1.7.html) is version 1.7 (codenamed <a href="http://phantomjs.org/release-names.html">"Blazing Star"</a>). Follow the official Twitter stream [@PhantomJS](http://twitter.com/PhantomJS) to get the frequent development updates.
|
||||||
|
|
||||||
**Note**: Please **do not** create a GitHub pull request **without** reading the [Contribution Guide](https://github.com/ariya/phantomjs/blob/master/CONTRIBUTING.md) first. Failure to do so may result in the rejection of the pull request.
|
**Note**: Please **do not** create a GitHub pull request **without** reading the [Contribution Guide](https://github.com/ariya/phantomjs/blob/master/CONTRIBUTING.md) first. Failure to do so may result in the rejection of the pull request.
|
||||||
|
|
||||||
|
@ -33,12 +33,12 @@ PhantomJS needs not be used only as a stand-alone tool. Check also some excellen
|
||||||
- [GhostDriver](http://github.com/detro/ghostdriver/) complements Selenium tests with a PhantomJS WebDriver implementation.
|
- [GhostDriver](http://github.com/detro/ghostdriver/) complements Selenium tests with a PhantomJS WebDriver implementation.
|
||||||
- [PhantomRobot](https://github.com/datakurre/phantomrobot) runs Robot Framework acceptance tests in the background via PhantomJS.
|
- [PhantomRobot](https://github.com/datakurre/phantomrobot) runs Robot Framework acceptance tests in the background via PhantomJS.
|
||||||
|
|
||||||
and many others [companion projects](http://code.google.com/p/phantomjs/wiki/WhoUsesPhantomJS).
|
and many others [related projects](https://github.com/ariya/phantomjs/wiki/Related-Projects).
|
||||||
|
|
||||||
## Questions?
|
## Questions?
|
||||||
|
|
||||||
- Explore the complete [documentation](http://code.google.com/p/phantomjs/wiki/PhantomJS?tm=6).
|
- Explore the complete [documentation](http://code.google.com/p/phantomjs/wiki/PhantomJS?tm=6).
|
||||||
- Read tons of [user articles](http://code.google.com/p/phantomjs/wiki/ExternalArticles) on using PhantomJS.
|
- Read tons of [user articles](https://github.com/ariya/phantomjs/wiki/Buzz) on using PhantomJS.
|
||||||
- Join the [mailing-list](http://groups.google.com/group/phantomjs) and discuss with other PhantomJS fans.
|
- Join the [mailing-list](http://groups.google.com/group/phantomjs) and discuss with other PhantomJS fans.
|
||||||
|
|
||||||
PhantomJS is free software/open source, and is distributed under the [BSD license](http://opensource.org/licenses/BSD-3-Clause). It contains third-party code, see the included `third-party.txt` file for the license information on third-party code.
|
PhantomJS is free software/open source, and is distributed under the [BSD license](http://opensource.org/licenses/BSD-3-Clause). It contains third-party code, see the included `third-party.txt` file for the license information on third-party code.
|
||||||
|
|
|
@ -1,49 +0,0 @@
|
||||||
# Get weather info for given address (or for the default one, "Mountain View")
|
|
||||||
|
|
||||||
page = require('webpage').create()
|
|
||||||
system = require 'system'
|
|
||||||
address = 'Mountain View' #< default value
|
|
||||||
|
|
||||||
# Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
|
|
||||||
page.onConsoleMessage = (msg) ->
|
|
||||||
console.log msg
|
|
||||||
|
|
||||||
# Print usage message, if no address is passed
|
|
||||||
if system.args.length < 2
|
|
||||||
console.log 'Usage: weather.coffee [address]'
|
|
||||||
else
|
|
||||||
address = Array.prototype.slice.call(system.args, 1).join(' ')
|
|
||||||
|
|
||||||
# Heading
|
|
||||||
console.log "*** Loading weather information for '#{address}' ***\n"
|
|
||||||
|
|
||||||
# Open Google "secret" Weather API and, onPageLoad, do...
|
|
||||||
page.open encodeURI("http://www.google.com/ig/api?weather=#{address}"), (status) ->
|
|
||||||
# Check for page load success
|
|
||||||
if status isnt 'success'
|
|
||||||
console.log 'Unable to access network'
|
|
||||||
else
|
|
||||||
# Execute some DOM inspection within the page context
|
|
||||||
page.evaluate ->
|
|
||||||
if document.querySelectorAll('problem_cause').length > 0
|
|
||||||
console.log "No data available for #{address}"
|
|
||||||
else
|
|
||||||
data = (s, e) ->
|
|
||||||
e = e or document
|
|
||||||
el = e.querySelector s
|
|
||||||
if el then el.attributes.data.value else undefined
|
|
||||||
|
|
||||||
console.log """City: #{data 'weather > forecast_information > city'}
|
|
||||||
Current condition: #{data 'weather > current_conditions > condition'}
|
|
||||||
Temperature: #{data 'weather > current_conditions > temp_f'} F
|
|
||||||
#{data 'weather > current_conditions > humidity'}
|
|
||||||
#{data 'weather > current_conditions > wind_condition'}\n
|
|
||||||
"""
|
|
||||||
|
|
||||||
forecasts = document.querySelectorAll 'weather > forecast_conditions'
|
|
||||||
for i in forecasts
|
|
||||||
console.log "#{ data 'day_of_week', i }: " +
|
|
||||||
"#{ data 'low', i }-" +
|
|
||||||
"#{ data 'high', i } F " +
|
|
||||||
"#{ data 'condition', i }"
|
|
||||||
phantom.exit()
|
|
|
@ -1,58 +0,0 @@
|
||||||
// Get weather info for given address (or for the default one, "Mountain View")
|
|
||||||
|
|
||||||
var page = require('webpage').create(),
|
|
||||||
system = require('system'),
|
|
||||||
address = "Mountain View"; //< default value
|
|
||||||
|
|
||||||
// Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
|
|
||||||
page.onConsoleMessage = function(msg) {
|
|
||||||
console.log(msg);
|
|
||||||
};
|
|
||||||
|
|
||||||
// Print usage message, if no address is passed
|
|
||||||
if (system.args.length < 2) {
|
|
||||||
console.log("Usage: weather.js [address]");
|
|
||||||
} else {
|
|
||||||
address = Array.prototype.slice.call(system.args, 1).join(' ');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Heading
|
|
||||||
console.log("*** Loading weather information for '" + address + "' ***\n");
|
|
||||||
|
|
||||||
// Open Google "secret" Weather API and, onPageLoad, do...
|
|
||||||
page.open(encodeURI('http://www.google.com/ig/api?weather=' + address), function (status) {
|
|
||||||
// Check for page load success
|
|
||||||
if (status !== "success") {
|
|
||||||
console.log("Unable to access network");
|
|
||||||
} else {
|
|
||||||
// Execute some DOM inspection within the page context
|
|
||||||
page.evaluate(function() {
|
|
||||||
if (document.querySelectorAll('problem_cause').length > 0) {
|
|
||||||
console.log('No data available for ' + address);
|
|
||||||
} else {
|
|
||||||
function data (s, e) {
|
|
||||||
var el;
|
|
||||||
e = e || document;
|
|
||||||
el = e.querySelector(s);
|
|
||||||
return el ? el.attributes.data.value : undefined;
|
|
||||||
};
|
|
||||||
|
|
||||||
console.log('City: ' + data('weather > forecast_information > city'));
|
|
||||||
console.log('Current condition: ' + data('weather > current_conditions > condition'));
|
|
||||||
console.log('Temperature: ' + data('weather > current_conditions > temp_f') + ' F');
|
|
||||||
console.log(data('weather > current_conditions > humidity'));
|
|
||||||
console.log(data('weather > current_conditions > wind_condition'));
|
|
||||||
console.log('');
|
|
||||||
|
|
||||||
var forecasts = document.querySelectorAll('weather > forecast_conditions');
|
|
||||||
for (var i = 0; i < forecasts.length; ++i) {
|
|
||||||
var f = forecasts[i];
|
|
||||||
console.log(data('day_of_week', f) + ': ' +
|
|
||||||
data('low', f) + '-' + data('high', f) + ' F ' +
|
|
||||||
data('condition', f));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
phantom.exit();
|
|
||||||
});
|
|
Loading…
Reference in New Issue