christianpraiss / osmosis Goto Github PK
View Code? Open in Web Editor NEWWeb-Scraping with Swift made easy
License: MIT License
Web-Scraping with Swift made easy
License: MIT License
Hi,
I am trying to use Osmosis to fetch data from a website. I made a button that calls a function where I set the osmosis scope. My issue is that when I click on the button for the first time, the data is fetched from the site, but if I click again on the button, I still get the same data even tough the data has changed on the website. Here's a snippet of my code:
import UIKit
import Osmosis
class ViewController: UIViewController {
@IBOutlet weak var quote: UILabel!
var array: [[String: AnyObject]] = []
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.quote.text = "This is my initial text."
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func getQuotes() {
var updateText: String = ""
Osmosis(errorHandler: { (error) -> Void in
print(error)
})
.get(NSURL(string: "http://www.excemple.com")!)
.find(OsmosisSelector(selector: ".wrapper"), type: .CSS)
.populate([
OsmosisPopulateKey.Single("div") : OsmosisSelector(selector: ".div")
], type: .CSS)
.list { (dict) -> Void in
self.array.append(dict)
// Cast self.array[0] to String
updateText = self.array[0]["div"] as! String
// Truncate the string to remove unwanted \n \t
updateText.removeAtIndex(updateText.startIndex)
updateText.removeAtIndex(updateText.startIndex)
updateText.removeAtIndex(updateText.endIndex.predecessor())
print(updateText)
//Update UI by the main thread (to avoid slow display update)
dispatch_async(dispatch_get_main_queue()) {
self.quote.text = updateText
}
}
.start()
}
@IBAction func refreshButton(sender: AnyObject) {
getQuotes()
}
How can I refresh my data fetch by Osmosis ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.