-
Notifications
You must be signed in to change notification settings - Fork 6
/
Amazon.scala
42 lines (28 loc) · 920 Bytes
/
Amazon.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package crawler
import scala.collection.JavaConversions._
import scala.concurrent._
import scala.util.Try
import java.net.URL
import net.ruippeixotog.scalascraper.browser.Browser
import net.ruippeixotog.scalascraper.dsl.DSL._
import net.ruippeixotog.scalascraper.dsl.DSL.Extract._
import models._
import play.api._
import play.api.Play.current
/**
* This crawler/scraper will scrape Amazon's product page for its description
*/
object Amazon {
implicit class AmazonURL(url: URL) {
private[this] lazy val browser = new Browser
def productDescription(): Try[Option[ProductDescription]] = Try {
Logger info s"Get Product Description - URL: $url"
val doc = browser.get(url.toString)
val results = doc >?> element("#productDescription p").map { e =>
ProductDescription(e.text)
}
Logger info s"URL: $url - Product Description: $results"
results
}
}
}