forked from nolanw/HTMLReader
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate playground to Swift 3 and project to Xcode 8.
- Loading branch information
Showing
9 changed files
with
70 additions
and
41 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,33 @@ | ||
//: HTMLReader – A WHATWG-compliant HTML parser | ||
import HTMLReader | ||
import XCPlayground | ||
|
||
XCPlaygroundPage.currentPage.needsIndefiniteExecution = true | ||
import PlaygroundSupport | ||
|
||
let homepage = "https://github.com/nolanw/HTMLReader" | ||
NSURLSession.sharedSession().dataTaskWithURL(NSURL(string: homepage)!) { | ||
(data, response, error) in | ||
|
||
URLSession.shared.dataTask(with: URL(string: homepage)!) { (data, response, error) in | ||
defer { PlaygroundPage.finishExecution(PlaygroundPage.current) } | ||
|
||
|
||
var contentType: String? = nil | ||
if let response = response as? NSHTTPURLResponse { | ||
if let response = response as? HTTPURLResponse { | ||
contentType = response.allHeaderFields["Content-Type"] as? String | ||
} | ||
if let data = data { | ||
let home = HTMLDocument(data: data, contentTypeHeader:contentType) | ||
if let div = home.firstNodeMatchingSelector(".repository-meta-content") { | ||
let whitespace = NSCharacterSet.whitespaceAndNewlineCharacterSet() | ||
print(div.textContent.stringByTrimmingCharactersInSet(whitespace)) | ||
} else { | ||
print("Failed to match .repository-meta-content, maybe the HTML changed?") | ||
} | ||
} else { | ||
|
||
guard let data = data else { | ||
print("No data received, sorry.") | ||
return | ||
} | ||
XCPlaygroundPage.finishExecution(XCPlaygroundPage.currentPage) | ||
|
||
let home = HTMLDocument(data: data, contentTypeHeader:contentType) | ||
|
||
guard let div = home.firstNode(matchingSelector: ".repository-meta-content") else { | ||
print("Failed to match .repository-meta-content, maybe the HTML changed?") | ||
return | ||
} | ||
|
||
print(div.textContent.trimmingCharacters(in: .whitespacesAndNewlines)) | ||
|
||
|
||
}.resume() | ||
|
||
PlaygroundPage.current.needsIndefiniteExecution = true |
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
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
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
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
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
2 changes: 1 addition & 1 deletion
2
HTMLReader.xcodeproj/xcshareddata/xcschemes/HTMLReader tvOS.xcscheme
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
2 changes: 1 addition & 1 deletion
2
HTMLReader.xcodeproj/xcshareddata/xcschemes/HTMLReader watchOS.xcscheme
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