title: How to use Spark-Scala to download a CSV file from the web?
body: <p>world,</p>
  
  <p>How to use Spark-Scala to download a CSV file from the web and load the file into a spark-csv DataFrame?</p>
  
  <p>Currently I depend on curl in a shell command to get my CSV file.</p>
  
  <p>Here is the syntax I want to enhance:</p>
  
  <pre><code>/* fb_csv.scala
  This script should load FB prices from Yahoo.
  
  Demo:
  spark-shell -i fb_csv.scala
  */
  
  // I should get prices:
  import sys.process._
  "/usr/bin/curl -o /tmp/fb.csv http://ichart.finance.yahoo.com/table.csv?s=FB"!
  
  import org.apache.spark.sql.SQLContext
  
  val sqlContext = new SQLContext(sc)
  
  val fb_df = sqlContext.read.format("com.databricks.spark.csv").option("header","true").option("inferSchema","true").load("/tmp/fb.csv")
  
  fb_df.head(9)
  </code></pre>
  
  <p>I want to enhance the above script so it is pure Scala with no shell syntax inside.</p>