Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Example Scraper 1
- val result: Future[Boolean] = scrape { implicit context =>
- get(virgin.loginPage) andThen { implicit context =>
- postForm(virgin.loginForm(username, password)) asHTML { implicit context =>
- doc =>
- val samlResponse = doc.$("#acsForm input[name=SAMLResponse]").value;
- val relayState = doc.$("#acsForm input[name=RelayState]").value;
- postForm(virgin.acsForm(samlResponse, relayState)) andThen { implicit context =>
- self ! UpdateState(context)
- complete(true)
- }
- }
- }
- }
- // Example Scraper 2
- val result: Future[Option[BillDetails]] = scrapeWithContext(scrapingContext) { implicit context =>
- get(virgin.home) asHTML { implicit context =>
- doc =>
- val totals = doc.$(".total").map(_.text)
- totals match {
- case billAmount :: balanceAmount :: Nil => complete(Some(BillDetails(billAmount, balanceAmount)))
- case _ =>
- after(2 seconds) {
- get(virgin.billingSnippet) asHTML { implicit context =>
- doc =>
- val totals = doc.$(".total").map(_.text)
- totals match {
- case billAmount :: balanceAmount :: Nil => complete(Some(BillDetails(billAmount, balanceAmount)))
- case _ => complete(None)
- }
- }
- }
- }
- }
- }
- // Example Collector
- spawn[VirginMediaScraper] { scraper =>
- scraper ? Login("mathewsonkt@hotmail.com", "Ovoaccess1") map {
- case LoggedIn =>
- log.info(s"Logged In")
- collect(scraper ? GetBillDetails, scraper ? GetPersonalDetails) {
- case (billDetails: BillDetails, personalDetails: PersonalDetails) =>
- log.info(s"${billDetails.toString} ${personalDetails.toString}")
- scraper ! PoisonPill
- case _ => log.info("Unable to get the bill and personal details")
- }
- case NotLoggedIn => log.info(s"Not Logged In")
- } recover {
- case ex: Exception => log.error(ex, "Unable to login")
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement