08-27-周三_17-09-29
This commit is contained in:
32
node_modules/phantom/samples/test_phantom.coffee
generated
vendored
Normal file
32
node_modules/phantom/samples/test_phantom.coffee
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
# This script demonstrates how phantomjs is used within Nodejs in replacement of
|
||||
# JSDOM
|
||||
phantom = require 'phantom'
|
||||
phantom.create (ph) ->
|
||||
ph.createPage (page) ->
|
||||
URL = 'http://www.mdscollections.com/cat_mds_accessories.cfm'
|
||||
page.open URL, (status) ->
|
||||
console.log 'Opened site? %s', status
|
||||
another_funny page, ph
|
||||
|
||||
another_funny = (page, ph) ->
|
||||
# query page for results
|
||||
page.evaluate ->
|
||||
|
||||
# function needs to be within the page evaluate callback
|
||||
funny = ->
|
||||
h2Arr = []
|
||||
results = document.querySelectorAll('.listing_product_name')
|
||||
for x in [0...results.length]
|
||||
h2Arr.push(results[x].innerHTML)
|
||||
return h2Arr
|
||||
|
||||
h2Arr = []
|
||||
pArr = []
|
||||
h2Arr = funny()
|
||||
return {
|
||||
h2: h2Arr
|
||||
}
|
||||
|
||||
, (result) ->
|
||||
console.log result
|
||||
ph.exit()
|
35
node_modules/phantom/samples/test_phantom.js
generated
vendored
Normal file
35
node_modules/phantom/samples/test_phantom.js
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
var phantom = require('phantom');
|
||||
|
||||
phantom.create(function(ph) {
|
||||
ph.createPage(function(page) {
|
||||
page.open('http://www.mdscollections.com/cat_mds_accessories.cfm',
|
||||
function(status) {
|
||||
console.log('Opened site? %s', status);
|
||||
another_funny(page, ph);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function another_funny(page, ph) {
|
||||
page.evaluate(function() {
|
||||
var h2Arr = [];
|
||||
var pArr = [];
|
||||
|
||||
function funny() {
|
||||
var h2Arr = [];
|
||||
var results = document.querySelectorAll('.listing_product_name');
|
||||
var i;
|
||||
for (i = 0; i < results.length; i++) {
|
||||
h2Arr.push(results[i].innerHTML);
|
||||
}
|
||||
return h2Arr;
|
||||
}
|
||||
|
||||
h2Arr = funny();
|
||||
return {h2: h2Arr};
|
||||
},
|
||||
function(result) {
|
||||
console.log(result);
|
||||
ph.exit();
|
||||
});
|
||||
}
|
35
node_modules/phantom/samples/test_phantom_10.coffee
generated
vendored
Normal file
35
node_modules/phantom/samples/test_phantom_10.coffee
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
# Setting cookie header to phantomJS from NodeJS - using Phantom version 0.4.1
|
||||
phantom = require 'phantom'
|
||||
|
||||
# Creates one process
|
||||
phantom.create (ph) ->
|
||||
|
||||
ph.addCookie 'cookie_name', 'cookie_value', 'localhost', ->
|
||||
console.log 'Cookie was added'
|
||||
|
||||
# Creates on page
|
||||
ph.createPage (page) ->
|
||||
|
||||
page.set('Referer', 'http://google.com')
|
||||
page.set 'settings.userAgent',
|
||||
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.1 (KHTML,
|
||||
like Gecko) Chrome/21.0.1180.89 Safari/537.1'
|
||||
page.open "http://localhost:9901/cookie", (status) ->
|
||||
console.log status
|
||||
someFunc = (aaa, my_obj) ->
|
||||
attribute_to_want = aaa
|
||||
h2Arr = []
|
||||
results = document.querySelectorAll(attribute_to_want)
|
||||
for x in [0...results.length]
|
||||
h2Arr.push(results[x].innerText)
|
||||
return {
|
||||
h2: h2Arr
|
||||
aaa: this.arguments
|
||||
obj: my_obj
|
||||
}
|
||||
|
||||
finishedFunc = (result) ->
|
||||
console.log result
|
||||
ph.exit()
|
||||
|
||||
page.evaluate someFunc, finishedFunc, 'div', {wahtt: 111}
|
30
node_modules/phantom/samples/test_phantom_2.coffee
generated
vendored
Normal file
30
node_modules/phantom/samples/test_phantom_2.coffee
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
# Success: Testing for wikipedia
|
||||
phantom = require 'phantom'
|
||||
phantom.create (ph) ->
|
||||
ph.createPage (page) ->
|
||||
page.open 'http://en.wikipedia.org/wiki/Main_Page', (status) ->
|
||||
console.log 'Opened site? %s', status
|
||||
another_funny page, ph
|
||||
|
||||
another_funny = (page, ph) ->
|
||||
# query page for results
|
||||
page.evaluate ->
|
||||
|
||||
# function needs to be within the page evaluate callback
|
||||
funny = ->
|
||||
h2Arr = []
|
||||
results = document.querySelectorAll('p')
|
||||
for x in [0...results.length]
|
||||
h2Arr.push(results[x].innerHTML)
|
||||
return h2Arr
|
||||
|
||||
h2Arr = []
|
||||
pArr = []
|
||||
h2Arr = funny()
|
||||
return {
|
||||
h2: h2Arr
|
||||
}
|
||||
|
||||
, (result) ->
|
||||
console.log result
|
||||
ph.exit()
|
25
node_modules/phantom/samples/test_phantom_3.coffee
generated
vendored
Normal file
25
node_modules/phantom/samples/test_phantom_3.coffee
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
# Fucked up - on using PhantonJS to get results from pages
|
||||
phantom = require 'phantom'
|
||||
|
||||
# Creates one process
|
||||
phantom.create (ph) ->
|
||||
# Creates on page
|
||||
ph.createPage (page) ->
|
||||
page.open "http://wikitravel.org/en/singapore", (status) ->
|
||||
console.log "opened page? ", status
|
||||
someFunc = (aaa) ->
|
||||
attribute_to_want = aaa
|
||||
h2Arr = []
|
||||
results = document.querySelectorAll(attribute_to_want)
|
||||
for x in [0...results.length]
|
||||
h2Arr.push(results[x].src)
|
||||
return {
|
||||
h2: h2Arr
|
||||
aaa: this.aaa
|
||||
}
|
||||
|
||||
finishedFunc = (result) ->
|
||||
console.log result
|
||||
ph.exit()
|
||||
|
||||
page.evaluate someFunc, finishedFunc, 'img'
|
27
node_modules/phantom/samples/test_phantom_4.coffee
generated
vendored
Normal file
27
node_modules/phantom/samples/test_phantom_4.coffee
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
# Success: Working model on using PhantonJS to get results from pages
|
||||
phantom = require 'phantom'
|
||||
|
||||
# Creates one process
|
||||
phantom.create (ph) ->
|
||||
# Creates on page
|
||||
ph.createPage (page) ->
|
||||
URL = "http://www.mdscollections.com/cat_mds_accessories.cfm"
|
||||
page.open URL, (status) ->
|
||||
console.log "opened page? ", status
|
||||
someFunc = (aaa) ->
|
||||
attribute_to_want = aaa
|
||||
h2Arr = []
|
||||
results = document.querySelectorAll(attribute_to_want)
|
||||
for x in [0...results.length]
|
||||
h2Arr.push(results[x].href)
|
||||
return {
|
||||
h2: h2Arr
|
||||
aaa: this.aaa
|
||||
sample_dom: results[0]
|
||||
}
|
||||
|
||||
finishedFunc = (result) ->
|
||||
console.log result
|
||||
ph.exit()
|
||||
|
||||
page.evaluate someFunc, finishedFunc, '.listing_product_name'
|
26
node_modules/phantom/samples/test_phantom_5.coffee
generated
vendored
Normal file
26
node_modules/phantom/samples/test_phantom_5.coffee
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
# Success: Working model on using PhantonJS to get results from pages
|
||||
phantom = require 'phantom'
|
||||
|
||||
# Creates one process
|
||||
phantom.create (ph) ->
|
||||
# Creates on page
|
||||
ph.createPage (page) ->
|
||||
page.open "http://www.deal.com.sg/deals/singapore", (status) ->
|
||||
console.log "opened page? ", status
|
||||
someFunc = (aaa, my_obj) ->
|
||||
attribute_to_want = aaa
|
||||
h2Arr = []
|
||||
results = document.querySelectorAll(attribute_to_want)
|
||||
for x in [0...results.length]
|
||||
h2Arr.push(results[x].src)
|
||||
return {
|
||||
h2: h2Arr
|
||||
aaa: this.arguments
|
||||
obj: my_obj
|
||||
}
|
||||
|
||||
finishedFunc = (result) ->
|
||||
console.log result
|
||||
ph.exit()
|
||||
|
||||
page.evaluate someFunc, finishedFunc, '#deal-main-pic img', {wahtt: 111}
|
15
node_modules/phantom/samples/test_phantom_6.coffee
generated
vendored
Normal file
15
node_modules/phantom/samples/test_phantom_6.coffee
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
# Test to see what kind of header values can be set
|
||||
phantom = require 'phantom'
|
||||
|
||||
# Creates one process
|
||||
phantom.create (ph) ->
|
||||
# Creates on page
|
||||
console.log ph
|
||||
ph.createPage (page) ->
|
||||
console.log page
|
||||
page.set('Referer', 'http://google.com')
|
||||
page.set 'settings.userAgent',
|
||||
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.1 (KHTML,
|
||||
like Gecko) Chrome/21.0.1180.89 Safari/537.1'
|
||||
page.open "http://localhost:9901", (status) ->
|
||||
ph.exit()
|
15
node_modules/phantom/samples/test_phantom_7.coffee
generated
vendored
Normal file
15
node_modules/phantom/samples/test_phantom_7.coffee
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
# Error --- Corner case scenario: page open was called multiple times. One for
|
||||
# each iframe loaded
|
||||
phantom = require 'phantom'
|
||||
|
||||
# Creates one process
|
||||
phantom.create (ph) ->
|
||||
# Creates on page
|
||||
ph.createPage (page) ->
|
||||
page.set('Referer', 'http://google.com')
|
||||
page.set 'settings.userAgent',
|
||||
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.1 (KHTML,
|
||||
like Gecko) Chrome/21.0.1180.89 Safari/537.1'
|
||||
page.open "http://www.meetup.com/sgphpug/members/37086072/", (status) ->
|
||||
console.log 'page open successfully'
|
||||
ph.exit()
|
15
node_modules/phantom/samples/test_phantom_8.coffee
generated
vendored
Normal file
15
node_modules/phantom/samples/test_phantom_8.coffee
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
# Corner case scenario: page open was called multiple times. One for each iframe
|
||||
# loaded
|
||||
phantom = require 'phantom'
|
||||
|
||||
# Creates one process
|
||||
phantom.create (ph) ->
|
||||
# Creates on page
|
||||
ph.createPage (page) ->
|
||||
page.set('Referer', 'http://google.com')
|
||||
page.set 'settings.userAgent',
|
||||
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.1 (KHTML,
|
||||
like Gecko) Chrome/21.0.1180.89 Safari/537.1'
|
||||
page.open "http://localhost:9901/iframes", (status) ->
|
||||
console.log 'page open successfully'
|
||||
ph.exit()
|
32
node_modules/phantom/samples/test_phantom_9.coffee
generated
vendored
Normal file
32
node_modules/phantom/samples/test_phantom_9.coffee
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
# Corner case scenario: page open was called multiple times. One for each iframe
|
||||
# loaded
|
||||
phantom = require 'phantom'
|
||||
|
||||
# Creates one process
|
||||
phantom.create (ph) ->
|
||||
# Creates on page
|
||||
ph.createPage (page) ->
|
||||
|
||||
page.set('Referer', 'http://google.com')
|
||||
page.set 'settings.userAgent',
|
||||
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.1 (KHTML,
|
||||
like Gecko) Chrome/21.0.1180.89 Safari/537.1'
|
||||
page.open "http://www.facebook.com/VintrySingapore", (status) ->
|
||||
console.log status
|
||||
someFunc = (aaa, my_obj) ->
|
||||
attribute_to_want = aaa
|
||||
h2Arr = []
|
||||
results = document.querySelectorAll(attribute_to_want)
|
||||
for x in [0...results.length]
|
||||
h2Arr.push(results[x].innerText)
|
||||
return {
|
||||
h2: h2Arr
|
||||
aaa: this.arguments
|
||||
obj: my_obj
|
||||
}
|
||||
|
||||
finishedFunc = (result) ->
|
||||
console.log result
|
||||
ph.exit()
|
||||
|
||||
page.evaluate someFunc, finishedFunc, 'div', {wahtt: 111}
|
Reference in New Issue
Block a user