-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathGetTextURL.scala
More file actions
31 lines (28 loc) · 1.21 KB
/
Copy pathGetTextURL.scala
File metadata and controls
31 lines (28 loc) · 1.21 KB
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
import org.apache.spark.{SparkConf,SparkContext}
import org.apache.spark.streaming.dstream.DStream
import org.apache.spark.streaming.{Seconds,StreamingContext}
import org.jsoup.Jsoup
import org.jsoup.nodes._
import java.util.Iterator
import scala.collection.JavaConverters._
import java.net.{ URL, MalformedURLException }
import scala.util.control.Exception._
object GetTextURL {
def main(args: Array[String]): Unit = {
val conf = new SparkConf().setAppName("GetTextURL").setMaster("local[1]")
val sc = new SparkContext(conf)
val html = scala.io.Source.fromURL("https://en.wikipedia.org/wiki/Donald_Trump").mkString
def processNode(node: Node){
if(node.isInstanceOf[TextNode] && !node.toString().equals(" ") && node.parentNode().nodeName().toString().equals("p"))
println(node.toString())
if(node.childNodeSize()>0)
node.childNodes().asScala.foreach(x => processNode(x))
}
val doc = Jsoup.parse(html)
processNode(doc)
//val list = html.split("\n").filter(_ != "")
//val rdds = sc.parallelize(list)
//val count = rdds.filter(_.contains("WWE")).count()
//rdds.saveAsTextFile("/Users/vinaya/Downloads/text")
}
}