Created
November 3, 2012 11:57
-
-
Save AJamesPhillips/4007170 to your computer and use it in GitHub Desktop.
phantomjs1.7 returning html elements from page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
complete | |
on page, got: 3 results: [object HTMLLIElement],[object HTMLLIElement],[object HTMLLIElement] | |
From page, got: 3 results: [object Object],, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
</head> | |
<body> | |
<ul> | |
<li>el1</li> | |
<li>el2</li> | |
<li>el3</li> | |
</ul> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
page = new WebPage; | |
returnHtml = () -> | |
nodes = document.evaluate("/html[1]/body[1]/ul[1]/li", document, null, XPathResult.ANY_TYPE, null) | |
results = (node while node = nodes.iterateNext()) | |
console.log "on page, got: #{results.length} results: #{results}" | |
return results | |
fn = () -> | |
console.log page.evaluate(-> document.readyState) | |
resultsFromPage = page.evaluate(returnHtml) | |
console.log "From page, got: #{resultsFromPage.length} results: #{resultsFromPage}" | |
phantom.exit() | |
page.onConsoleMessage = (msg) -> | |
console.log msg | |
return null | |
page.open("http://0.0.0.0:4000/page.html",fn) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment